Curl calls the Jenkins API control job

Source: Internet
Author: User

1.curl
Curl is an open source file Transfer tool that works with URL syntax in the command line mode. It is widely used in Unix, multiple Linux distributions, and has a ported version of DOS and Win32, Win64.

1.1 getting page/resource files
Curl http://www.baidu.com
Gets the page that the URL points to, and if the URL points to a resource file, such as a file or a picture, the resource file can be downloaded directly to the local

1.2 Submit a GET request
Curl "Wwww.baidu.com?wd=jenkins"

1.3 Submit a POST request
Curl-d "Wd=jenkins" www.baidu.com


2.jenkins

2.1 Running the job

2.1.1 Non-parametric task
Curl-x POST http://localhost:8080/jenkins/job/plugin%20demo/build--user admin:admin

2.1.2 Task with reference
Do not set parameters/use default parameters
Curl-x POST http://localhost:8080/jenkins/job/commandTest/buildWithParameters--user admin:admin

2.1.3 Setting Parameter Method 1
Curl-x POST http://localhost:8080/jenkins/job/commandTest/buildWithParameters-d port=80

2.1.4 Setting Parameter Method 2
Curl-x POST http://localhost:8080/jenkins/job/commandTest/buildWithParameters-d port=80--data-urlencode json= ' "{\" Parameter\ ": [{\" name\ ": \" port\ ", \" value\ ": \" 80\ "}]}" '

2.1.5 Multi-parameter
Http://localhost:8080/jenkins/job/commandTest/buildWithParameters-d Param1=value1&param2=value

2.2 Create Job

2.2.1 Need to create a directory

1). Create a job Directory
~/.jenkins/jobs/jobfromcmd
2). Create a config. file (can be copied from another project)
3). Run the command
Curl-x POST http://localhost:8080/jenkins/createItem?name=jobfromcmd--user admin:admin--data-binary "@config. xml"- H "Content-type:text/xml"

2.2.2 Do not need to create a directory
1). Create a config. file (can be copied from another project)
2). Run the command (in the same directory as the config)
Curl-x POST http://localhost:8080/jenkins/createItem?name=jobfromcmd--user admin:admin--data-binary "@config. xml"- H "Content-type:text/xml"

2.2.3 using the console directly without creating an XML file (run XML content into the console)
Echo ' <?xml version= ' 1.0 ' encoding= ' UTF-8 '?><project>...</project> ' | Curl-x post-h ' content-type:text/xml '-D @-http://localhost:8080/jenkins/createItem?name=jobfromcmd


2.3 Delete Job
Curl-x POST Http://localhost:8080/jenkins/job/jobfromcmd/doDelete

2.4 Querying the status of a job
Curl--silent ${jenkins_server}/job/job_name/lastbuild/api/json

2.5 Automatic Disable Project:
Curl--user ${username}:${password}-o/dev/null--data Disable jenkins_url/job/jobname/disable

2.6 Get num of Build
Curl--silent ${jenkins_server}/job/job_name/lastbuild/buildnumber

2.7 Obtaining NUM for the most recent successful build
Curl--silent ${jenkins_server}/job/job_name/laststablebuild/buildnumber

More Curl References:
Https://curl.haxx.se/docs/manpage.html
Https://curl.haxx.se/docs/manual.html

Curl calls the Jenkins API control job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.