通过URL登录Jenkins

时间:2013-06-02 05:42:45

标签: java jenkins

我想从Jenkins Server下载一个文件(slave-agent.jnlp),需要用户密码。 (使用Java)

由于无法在URL中提供用户和密码,因此可以实现的方式是什么?

谢谢, 多伦

2 个答案:

答案 0 :(得分:2)

这是我用来启动我的从属节点的shell脚本:

#!/bin/bash

if [ ! -e slave.jar ] || [ ! -e commons-codec-1.7.jar ]; then
   curl -O "https://my.jenkins.host/jnlpJars/slave.jar"
   curl -O "https://my.nexus.repo/service/local/repositories/central/content/commons-codec/commons-codec/1.7/commons-codec-1.7.jar"
fi

nohup java -jar slave.jar -cp commons-codec-1.7.jar \
     -jnlpUrl https://my.jenkins.host/computer/My_slave/slave-agent.jnlp \
     -jnlpCredentials myuser:myusertoken \
     > $0.log 2>&1 &

注意:

  • 我的奴隶在特定的基础上旋转,所以我选择注册一个名为“My_slave”的奴隶,然后使用奴隶的JNLP URL在另一台机器上运行奴隶。这意味着仍然集中配置了从站
  • 可能不再需要添加commons-codec jar。这是对身份验证错误JENKINS-9679
  • 的解决方法
  • 我在Jenkins用户帐户中配置了用户令牌。这避免了我必须将我的密码放在shell脚本中

其他说明:

  • 使用SSH插件是配置从属设备的最简单方法,前提是从属节点是unix并且您已正确设置SSH密钥。这种JNLP方法有效,但很繁琐。
  • 另一个有趣的插件是swarm plugin。我没有使用它,但我喜欢奴隶不必预先注册的方式。

更新

关于如何使用swarm插件的简明博客:

答案 1 :(得分:0)

可以在网址中提及用户名和密码,如下所示:

http://username:password@example.com/