我知道如何使用jenkins-cli从命令行在Jenkins中创建一个作业,但我不知道如何指定新作业在哪个视图中。它是在没有视图的情况下创建的。
有没有办法指定我想要的视图?
或
是否有后续命令将我新创建的作业移动到某个视图?
有关jenkins-cli提供的命令的文档没有详细介绍每个命令。
为完整起见,以下是命令:
首次登录:
java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://jenkins.example.com:8080 login --username user
Password: (I type the password here)
Successfully loaded native POSIX impl.
然后是实际的命令:
java -jar /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar -s http://jenkins.example.com:8080 create-job NewJobName < ~/jobs/template/config.xml
工作成功创建。
答案 0 :(得分:2)
好的,我知道了!但是,我是通过使用curl直接通过API完成的。方法如下:
curl -i -X POST --user "username:xxx" --data-binary "@NewJob.xml" -H "Content-Type: text/xml" http://jenkins.example.com/view/myView/createItem?name=NewJob
,其中
xxx is the API token
NewJob.xml is the configuration XML for the new job
myView is the desired view where the new job will be
NewJob is the name of the new job
答案 1 :(得分:0)
你也可以通过jenkins_api_client ruby gem来实现。
@client = JenkinsApi::Client.new(:server_url => 'ip_address')
@client.view.add_job("view_name","job_name")
这意味着你将使用ruby。