Skip to content

Instantly share code, notes, and snippets.

@stuart-warren
Last active September 4, 2025 08:12
Show Gist options
  • Select an option

  • Save stuart-warren/7786892 to your computer and use it in GitHub Desktop.

Select an option

Save stuart-warren/7786892 to your computer and use it in GitHub Desktop.
Create a job in Jenkins (or folder) using the HTTP API
# 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/
@AnthonyClink

Copy link
Copy Markdown

this is a life saver thanks

@Balasekhar

Copy link
Copy Markdown

:)

@PratikshaKP

Copy link
Copy Markdown

What does mode stand for in the last API?

@ygaller

ygaller commented Feb 24, 2016

Copy link
Copy Markdown

Another way to check whether job exists:
curl -XGET 'http://jenkins/job/yourJobName/api/json' --user user.name:YourAPIToken
This returns either 200 or 404 depending on whether the job already exists.

@harenderbits

Copy link
Copy Markdown

HI
Can i send string parameters and there value ....while creating job with curl. I need to create a job which is parameterized through the api.

@pesetskyps

Copy link
Copy Markdown

thank you, helped a lot

@ilanni2460

Copy link
Copy Markdown

very good tks

@fboukezzoula

Copy link
Copy Markdown

Thanks. I will try it on Monday at desk :o)

@razbomi

razbomi commented Jul 6, 2017

Copy link
Copy Markdown

🎉

@jingjingpiggy

Copy link
Copy Markdown

Hi, do you have jenkins buildjob.sh? :)

@serbixote

Copy link
Copy Markdown

Hi @stuart-warren, for the create folder request, from parameter is needed?
According to https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/hudson/model/ItemGroupMixIn.java
from parameter is only used when the mode parameter equals "copy".

Regards!

@vamsikrishnakoni

Copy link
Copy Markdown

Hi
Any API we can add the user to the Jenkins with read and build access for a jenkins job ?

Thanks
Vamsi

@serbixote

Copy link
Copy Markdown

Hi @vamsikrishnakoni
You can take a look at RoleBasedAuthorizationStrategy.java. There are examples with cURL for managing roles.

I'm not sure whether you can add the user and assign a role in once. Hope it helps you 😄

@Eric-Fontana-Bose

Copy link
Copy Markdown

How do you "Move" a job which is not currently in a folder to a newly created folder? Using whatever API possible?

@arellano-gustavo

Copy link
Copy Markdown

Is it possible to send instead xml content, only json ? How?

@Asgoret

Asgoret commented Jul 22, 2020

Copy link
Copy Markdown

Thanks! It's really to save my time!

@abdennour

Copy link
Copy Markdown

thanks man!

@sw-dev-code

Copy link
Copy Markdown

Thank you for the commands. I'm just wondering if there is an instruction on how to do the same thing with the config file in JSON format if that is possible?

Also, does anybody know about the document or tutorial on how to create config.xml for a new job?

Thank you in advance.

@sauravrout

Copy link
Copy Markdown

Thanks for the command, I am wondering if there is an option to overwrite an existing job.

@syedahaider97

Copy link
Copy Markdown

Thanks, this worked great!

@minaxijoshi3101

Copy link
Copy Markdown

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