Jenkins用户的Jenkins CLI设置 - 方法

时间:2017-12-12 10:49:09

标签: shell jenkins jenkins-cli

我在Jenhat服务器上运行Jenkins 1.647。我尝试使用基于参数的Execute Shell中的Jenkins Jobs从命令行创建作业。 我尝试过如下,但没有一个命令正常工作。我的jenkins身份验证基于ldap。

通过Jenkins Execute Shell执行这些命令。 命令1

java -jar jenkins-cli.jar -s https://buildserver:8080/jenkins/ get-job job-template -i /var/lib/jenkins/.ssh/id_rsa
[WARN] Failed to authenticate with your SSH keys. Proceeding as anonymous
No such job 'job-template'
java -jar jenkins-cli.jar get-job JOB [--username VAL] [--password VAL] [--password-file VAL]
Dumps the job definition XML to stdout.
 JOB                 : Name of the job
 --username VAL      : User name to authenticate yourself to Jenkins
 --password VAL      : Password for authentication. Note that passing a
                       password in arguments is insecure.
 --password-file VAL : File that contains the password
Build step 'Execute shell' marked build as failure

命令-2

java -jar jenkins-cli.jar -s http://buildserver:8080/jenkins/ --username my-name --password-file /tmp/password-file

/tmp/password-file
xxxxx

是否有办法使用Jenkins用户API令牌使上述命令有效。请建议。

1 个答案:

答案 0 :(得分:0)

使用

java -jar jenkins-cli.jar -s https://buildserver:8080/jenkins/ -auth USER:TOKEN get-job job-template

您需要在JENKINS_URL:PORT/user/YOUR_USER/configure下创建一个API令牌