• 安装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 生成步骤

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


     

  • 相关阅读:
    2022年浙大数据结构MOOC作业题目集
    【电力运维】浅谈电力通信与泛在电力物联网技术的应用与发展
    阿里云服务器购买之后设置密码、安全组、增加带宽、挂载云盘教程
    【17】建立数据通路(上):指令+运算=CPU
    【JS面试题】面试官问我:遍历一个数组用 for 和 forEach 哪个更快?
    【网络安全】Kail操作系统
    Javaweb基础-前端工程化学习笔记
    编译安装gcc-11及可能遇到的bug
    虹科示波器 | 汽车免拆检修 | 2010款江铃陆风X8车发动机怠速抖动、加速无力
    网络基础入门(网络基础概念详解)
  • 原文地址:https://blog.csdn.net/Blue___Ocean/article/details/128017539