Jenkins: import a job to another server
Tags: jenkins, devops
Published: 2019-03-13 19:05:15

---
title: Jenkins: import a job to another server
published: true
tags: Jenkins,devops
canonical_url: https://rtfm.co.ua/en/jenkins-import-a-job-to-an-another-server/
---

![](https://rtfm.co.ua/wp-content/uploads/2016/01/Jenkins.sh-600x600-e1453134979914.png)We have an old Jenkins with a bunch of iOS jobs which needs to be copied to a new Jenkins instance.

[Documentation](https://wiki.jenkins.io/display/JENKINS/Administering+Jenkins#AdministeringJenkins-Moving%2Fcopying%2Frenamingjobs) suggests to:

> Move a job from one installation of Jenkins to another by simply copying the corresponding job directory.

I.e. the first solution is just to copy a whole `jobs` directory or copy a per-project job’s catalog.

Disadvantage (or advantage – depends on an exact task) of such approach is that with a job’s directory a whole its history, artifacts, logs etc will be copied as well.

Another solution is to use the [Jenkins CLI](https://wiki.jenkins.io/display/JENKINS/Jenkins+CLI) and allows to copy a full job’s configuration – but it will be created “from scratch”.

### Jenkins CLI

Go to _Manage Jenkins > Jenkins CLI_ and download the CLI’s jar-file:

[![](https://rtfm.co.ua/wp-content/uploads/2019/03/Screenshot_20190313_111842.png "Jenkins: перенос задач между серверами")](https://rtfm.co.ua/wp-content/uploads/2019/03/Screenshot_20190313_111842.png)

[![](https://rtfm.co.ua/wp-content/uploads/2019/03/Screenshot_20190313_111956.png "Jenkins: перенос задач между серверами")](https://rtfm.co.ua/wp-content/uploads/2019/03/Screenshot_20190313_111956.png)

Download:

```
$ sudo wget -O /usr/local/bin/jenkins-cli.jar https://jenkins.example.com/jnlpJars/jenkins-cli.jar
```

Check it – in `-auth` pass your _user:pass_ or _user:api_token_, in `-s` – Jenkin’s host URL, here it’s running locally using Jenkin’s own CLI file:

```
root@jenkins:/backups# java -jar /data/jenkins/war/WEB-INF/jenkins-cli.jar -auth user:pass -s http://localhost:8080/ version
2.89.4
```

Now import the _Unit Test_ job from the _iOS Projectname_ directory into the `Projectname_Unit_Test_job.xml` file:

```
root@jenkins:/backups# java -jar /data/jenkins/war/WEB-INF/jenkins-cli.jar -auth user:pass -s http://localhost:8080/ get-job 'iOS Projectname/Unit Test' > Projectname_Unit_Test_job.xml
```

Check the file’s content:

```
root@jenkins:/backups# head Projectname_Unit_Test_job.xml
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description>Runs test, and delivers feedback to slack</description>
<keepDependencies>false</keepDependencies>
<properties>
<com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.29.3">
<projectUrl>https://github.com/Projectname-dev/Projectname-iOS/</projectUrl>
<displayName></displayName>
</com.coravy.hudson.plugins.github.GithubProjectProperty>
```

And export it to the _iOS Projectname_ on a new Jenkins server: read the file’s content using the `cat` and then pass data to the CLI via pipe `|`:

```
root@jenkins:/backups# cat Projectname_Unit_Test_job.xml | java -jar /data/jenkins/war/WEB-INF/jenkins-cli.jar -auth user:pass -s https://ci.example.com create-job 'iOS Projectname/Unit Test'
```

Check it:

[![](https://rtfm.co.ua/wp-content/uploads/2019/03/Screenshot_20190313_183742.png "Jenkins: перенос задач между серверами")](https://rtfm.co.ua/wp-content/uploads/2019/03/Screenshot_20190313_183742.png)

Done.

### Similar posts

- <small>02/08/2017</small> [Jenkins: sandbox.RejectedAccessException: Scripts not permitted to use](https://rtfm.co.ua/jenkins-sandbox-rejectedaccessexception-scripts-not-permitted-to-use/)<small> (0)</small>  
- <small>02/09/2017</small> [Azure: подключение дополнительного диска к VM и миграция Jenkins](https://rtfm.co.ua/azure-podklyuchenie-dopolnitelnogo-diska-k-vm-i-migraciya-jenkins/)<small> (0)</small>   
- <small>10/18/2017</small> [Jenkins: миграция RTFM 2.6 – Jenkins Pipeline для Ansible](https://rtfm.co.ua/jenkins-migraciya-rtfm-2-6-jenkins-pipeline-dlya-ansible/)<small> (8)</small>  
- <small>09/22/2017</small> [Jenkins: Pipeline, Groovy, Ansible и VM provisioning](https://rtfm.co.ua/jenkins-pipeline-groovy-ansible-i-vm-provisioning/)<small> (0)</small>