CyberKeeda In Social Media
Showing posts with label Jenkins. Show all posts
Showing posts with label Jenkins. Show all posts

How to export and import Jenkins job.

If you have multiple jenkins instances, there might be a requirement to export an existing jenkins job, that could be further imported into the newer jenkins instance.

We will learn how to do the export/import of jenkins job using jenkins cli.

How to Export existing Jenkins job.

  • Jenkins Home Page 
  • Manage Jenkins
  • Jenkins CLI.
  • Download  jenkins-cli.jar

  • Click on Jenkins CLI.

Once file "jenkins-cli.jar" file has been downloaded, we are ready to export our Jenkins job, lets do it.
Open your terminal and run the below commands.

Authenticate and List down your jobs to identify the one, which one you want to export, replace "your-jenkins-server-url:your_server_port" from your source jenkins server's url and port.

cyberkeeda@jenkins-master:~$ java -jar jenkins-cli.jar -s "http://your-jenkins-server-url:your_server_port" -auth UserName:Password  list-jobs

docker ps

Now, from above enlisted jobs i want to export the one named as "djpass-docker-app".
Run the below command and replace the highlighted one by yours.

cyberkeeda@jenkins-master:~$  java -jar jenkins-cli.jar -s "http://your-jenkins-server-url:your_server_port" -auth UserName:Password get-job djpass-docker-app > djpass-docker-app.xml

We have successfully exported our jenkins job named as "djpass-docker-app" as an xml file named as "djpass-docker-app.xml"

How to import Jenkins job to different Jenkins server.

  • Go to your new jenkins server dashboard, where you want to import.
  • Follow the same above steps to download the jenkins-cli.jar file.
  • Ensure you are ready with "jenkins-cli.jar" and your exported jenkins job XML file with you.
Now run the below command to import your jenkins job xml file to new jenkins server.
Note : Replace the highlighted one by yours.

cyberkeeda@jenkins-slave:~$  java -jar jenkins-cli.jar -s "http://your-Newjenkins-server-url:your_server_port" -auth UserName:Password create-job new-djpass-docker-app < djpass-docker-app.xml

Hoah !!! Thats it, check your dashboard to verify the same.

Read more ...

How to install Jenkins on Ubuntu 18.04 Bionic

Here we go, proceed with the below steps.

  • Mandatory requirement : Jave aka OpenJDK.
$  sudo apt install openjdk-8-jdk
Once installed verify the installation using the below command.
$  java -version

  • Installing Jenkins.

Official Ubuntu ships with older versions of jenkins, why lag behind let's add the new sources to install the latest version.

  • Add repository key first.
$  wget -q -O - | sudo apt-key add -
  • Once you got an OK confirmation, let's proceed to add debian package repository address to the our server's source list.
$  sudo sh -c 'echo deb binary/ > /etc/apt/sources.list.d/jenkins.list'
  • Now we are almost ready to install jenkins, lets make an update now
$  wget -q -O - | sudo apt-key add -
  • Here we go, install jenins now
$  sudo apt install jenkins

  • Start Jenkins

$  sudo systemctl start jenkins

    Access Admin Password to login to Jenkins UI.
    Open CLI, hit below cat command and grab the initial login password.

    $  sudo cat /var/lib/jenkins/secrets/initialAdminPassword

    Login to UI.

    $  http://<Your Jenkins Server IP>:8080/

      Further steps are self explanatory, install suggested plugins and change the initial admin password with your. 

      Read more ...
      Designed By Jackuna