• 安装Jenkins并在ruby中访问


    1. 安装Jenkins

    最近不知道为啥,根据官网Linux安装Jenkins的时候下不来安装包,提示连接超时。尝试多次无果后决定在window上安装

    1. curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
    2. curl: (7) Failed to connect to pkg.jenkins.io port 443: Connection timed out

    1.1.下载了一个jenkins.msi

    安装步骤  Windows

    安装到这步的时候,由于公司电脑权限问题我无法打开“Local Security Policy” 导致无法继续安装。 

    1.2. 下载war包安装

    大家如果装的是java8, 建议可以下载老一点的版本,比如2.2xx, 最新版用的是java11,不兼容。

    下载地址:jenkins.war

    安装步骤:WAR files

    贴上内容:

    The Jenkins Web application ARchive (WAR) file can be started from the command line like this:

    1. Download the latest Jenkins WAR file to an appropriate directory on your machine

    2. Open up a terminal/command prompt window to the download directory

    3. Run the command java -jar jenkins.war

    4. Browse to http://localhost:8080 and wait until the Unlock Jenkins page appears

    5. Continue on with the Post-installation setup wizard below

    Notes:

    • This process does not automatically install any specific plugins. They need to installed separately via the Manage Jenkins > Manage Plugins page in Jenkins.

    • You can change the port by specifying the --httpPort option when you run the java -jar jenkins.war command. For example, to make Jenkins accessible through port 9090, then run Jenkins using the command:
      java -jar jenkins.war --httpPort=9090

    有时候因为公司代理可能没法安装插件:可以通过Manage Jenkins ->Plugin Manager->Advanced->HTTP Proxy Configuration 配置好代理就可以了。

    配置job的时候可以使用这个方式模拟sleep

    1. echo "---start---"
    2. ping 127.0.0.1 -n 5 -w 1000 > nul
    3. echo "---end---"

    好啦,Jenkins安装成功啦。

    2.在ruby环境中调用Jenkins

    2.1连接超时

    1. 2.6.5 :005 > client
    2. => #>, @log_level=1, @crumbs_enabled=nil, @follow_redirects=nil, @jenkins_path="", @timeout=120>, @http_open_timeout=10>, @http_read_timeout=120>
    3. 2.6.5 :004 > client.api_get_request("")
    4. Traceback (most recent call last):
    5. 1: from (irb):4
    6. Net::OpenTimeout (execution expired)

    使用下面命令测一下正常

    traceroute 10.x.x.x -p 8080
    

    后来发现设置代理后可以正常访问

    http_proxy=http://代理IP:8080 rails c

    2.2 调用接口时总是提醒“ForbiddenWithCrumb: Access denied”

    1. I, [2022-11-28T02:33:38.752464 #22057] INFO -- : Crumb expired. Refetching from the server.
    2. I, [2022-11-28T02:33:39.375018 #22057] INFO -- : Retrying: 3 out of 3 times...
    3. E, [2022-11-28T02:33:39.375166 #22057] ERROR -- : JenkinsApi::Exceptions::ForbiddenWithCrumb: Access denied. Please ensure that Jenkins is set up to allow access to this operation. A crumb was used in attempt to access operation. Access denied. Please ensure that Jenkins is set up to allow access to this operation.

    通过创建一个token, 然后替换掉密码就可以啦。

    token 生成步骤

    好啦,我已经可以成功调用啦 


     

  • 相关阅读:
    【Ant Design Table + React】表格列伸缩实现
    【leetcode】【剑指offer Ⅱ】045. 二叉树最底层最左边的值
    QT 知:qmake 手册
    transformer 总结(超详细-初版)
    【WSL2】CENTOS7 安装与配置
    Git——分支(详细解释)
    实战文档:彻底搞懂JVM+Linux+MySQL+Netty+Tomcat+并发编程
    绝了,这20款可视化大屏模板太酷炫了(含源码)
    日志门面技术
    hyper-v安装 windows10虚拟机后,登录一直是锁屏界面,无法开启增强会话
  • 原文地址:https://blog.csdn.net/Blue___Ocean/article/details/128017539