Last active
March 8, 2024 16:20
-
-
Save stuart-warren/7786892 to your computer and use it in GitHub Desktop.
Create a job in Jenkins (or folder) using the HTTP API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check if job exists | |
curl -XGET 'http://jenkins/checkJobName?value=yourJobFolderName' --user user.name:YourAPIToken | |
# with folder plugin | |
curl -s -XPOST 'http://jenkins/job/FolderName/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken | |
# without folder plugin | |
curl -s -XPOST 'http://jenkins/createItem?name=yourJobName' --data-binary @config.xml -H "Content-Type:text/xml" --user user.name:YourAPIToken | |
# create folder | |
curl -XPOST 'http://jenkins/createItem?name=FolderName&mode=com.cloudbees.hudson.plugins.folder.Folder&from=&json=%7B%22name%22%3A%22FolderName%22%2C%22mode%22%3A%22com.cloudbees.hudson.plugins.folder.Folder%22%2C%22from%22%3A%22%22%2C%22Submit%22%3A%22OK%22%7D&Submit=OK' --user user.name:YourAPIToken -H "Content-Type:application/x-www-form-urlencoded" | |
# see http://jenkins/api/ |
Thanks, this worked great!
00:19:39 % Total % Received % Xferd Average Speed Time Time Time Current
00:19:39 Dload Upload Total Spent Left Speed
00:19:39
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 550 100 550 0 0 7142 0 --:--:-- --:--:-- --:--:-- 7142
00:19:39
00:19:39
00:19:39
00:19:39 <title>Error 403 No valid crumb was included in the request</title>
00:19:39
00:19:39
HTTP ERROR 403 No valid crumb was included in the request
00:19:39
00:19:39
00:19:39
00:19:39
00:19:39
00:19:39
URI: | /createItem |
---|---|
STATUS: | 403 |
MESSAGE: | No valid crumb was included in the request |
SERVLET: | Stapler |
00:19:39
Powered by Jetty:// 10.0.16
00:19:39
00:19:39
00:19:39
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the command, I am wondering if there is an option to overwrite an existing job.