Hello everyone welcomes back once again to Selenium Webdriver tutorial series. Today we will discuss how to Import and export jobs in Jenkins using CLI (Command line interface).
If you are completely new to Jenkins then you must have to visit below post.
Selenium Integration with Jenkins.
Get more information about CLI
Tips for Import and export jobs in jenkins
1- When you have multiple instances of Jenkins and you want to import and export some jobs then you can try below methods.
2- You can backup all Jobs using CLI which is most important
Follow below steps Import and export jobs in jenkins
Export the job
Step 1- Open Jenkins and Go to the job which you want to export.
Copy the name and store somewhere
Click on Manage jenkins options
Step 2- Click on Jenkins CLI which will open CLI window
Step 3- Now download CLI Jar as shown below and save in drive
Notes- We will use some commands which will help us to do our job.
get-job- this will export the job in XML file.
create-job – this will import the job from XML and will create job in Jenkins.
Step 4- Once you have jar ready use below command to export job in XML format.
[pullquote align=”normal”]java -jar jenkins-cli.jar -s http://url-of-server get-job myjob > myjob.xml [/pullquote]
Step 5- Once job exported you can check the job in below location in your local system
C > User > Your UserName > xml which we created
Import the job in Jenkins
Step 6- Now we can use below commands to upload or create new job in jenkins.
[pullquote align=”normal”] java -jar jenkins-cli.jar -s http://url-server create-job newjobname < xml-want-upload.xml [/pullquote]
Step 7- Once you are done check Jenkins and you will get new job ready.
I hope you have enjoyed this article. If you have any doubt then post in our Selenium forum.
Please comment below for any feedback.
sarah says
Do you have more article about Jenkins CLI? i am looking to export the build status to CSV
Mukesh Otwani says
Hi Sarah,
There are more videos on Jenkins CLI in pipeline. I’ll post them soon, please stay tuned…:)
Pranoy says
Nice article!
Mukesh Otwani says
Thanks bro…:)
samba says
Hi Mukesh Otwani,
I am getting the following error while exporting
ERROR: anonymous is missing the Overall/Read permission
Mukesh Otwani says
Hi Samba,
Are you doing jobs import between different verions of Jenkins?
Priyanshi Ahuja says
Please suggest me, Which is good approach to design Framework. Data Driven or Hybrid … Currently I am learning Selenium Tutorials online ….. But I think i need some training ….
Mukesh Otwani says
Hi Priyanshi,
Hope below course will help you http://learn-automation.usefedora.com/courses/selenium-frameworks-and-selenium-question-answers
Preetish Kumar Mahato says
i am facing problm java -jar jenkins-cli.jar -s http://url-of-server get-job myjob > myjob.xml is not working somewere i am geting wrong.. can u plzs help me mukesh .
Mukesh Otwani says
Hey Preetish,
Above is just a syntax have u made the changes like url and other things.
Hadeel says
Hi Mukash ,
I’m facing problems in running my test through Jenkins to a server using chrome driver as the following error keep showing : org.openqa.selenium.WebDriverException: unknown error: unable to discover open pages
Can you help me in this ?
Mukesh Otwani says
Hey Hadeel,
Which version of Selenium you are using. Selenium 3 is released so you can update Selenium and try again.
sahil says
Hi Mukesh,
Could create a video tutorial for Jenkins CLI because i don’t know how to set up CLI and backup all Jobs.
Thanks
Sahil
Mukesh Otwani says
Hey Sahil,
Here you go http://learn-automation.com/selenium-integration-with-jenkins/