There are a large number of old jobs on Jenkins that don't need to be run. We want to disable these jobs in batches. Later, we found that Jenkins provided a very simple way to operate through curl.
A simple Bash script for disable jenkins job is written as follows:
The code is as follows: |
Copy code |
#! /Bin/bash Jobs = "my-test-job-1 my-test-job-2 my-test-job-3" User = "user" Password = "password" Curl = "curl -- user $ user: $ password" Jenkins_url = "http://myjenkins.com" For j in $ jobs Do Disable_url = "$ curl-o/dev/null -- data disable $ jenkins_url/job/$ j/disable" # Enable_url = "$ curl-o/dev/null -- data enable $ jenkins_url/job/$ j/enable" Echo $ disable_url $ ($ Disable_url) Done |
Of course, to enable a job, use "enable_url" in the script.
You can also use curl to create a Jenkins job. You can refer to the following articles:
Simple tutorial on using curl to operate hudson/Jenkins on a command line