Update Jenkins which is currently running as a Linux service - jenkins

How do I update jenkins from a existing jenkins install running as a Linux service without loosing any jobs or config?

First, you need to find where your jenkins.war file is installed:
locate jenkins.war
On my Centos machine, it's here: /usr/share/jenkins/jenkins.war
Stop the Jenkins service:
service jenkins stop
Next, you can backup the existing jenkins.war file:
cd /usr/share/jenkins
mv jenkins.war jenkins-1.586.war
And to finish, please copy the new jenkins.war file in the same location:
cp jenkins.war /usr/share/jenkins/jenkins.war
Restart the Jenkins service:
service jenkins start
It should work and you should retrieve your Jenkins configuration (which is stored in your Jenkins home folder).

Related

How to know port number in jenkins?

I downloaded the Jenkins.war file and ran the command java -jar jenkins.war in my war file directory. It started Jenkins on the default port 8080 but now I want to change the Jenkins default port as I am running tomcat on port 8080. I did not found any Jenkins.xml file in my C:/User/Username/.jenkins folder. How to change the default port for Jenkins in this case?
If you need to run Jenkins on another port, just use the following syntax: java -jar jenkins.war -httpPort=<port-number>
For example, java -jar jenkins.war -httpPort=9090
I would suggest you run Jenkins as a service instead of running it using command line. This will ensure Jenkins keeps running when you restart your system.
Note: Regarding missing jenkins.xml file, i too don't have it in my installation dir. However, if you install Jenkins as a service using the steps provided here, it will then generate the jenkins.xml file. FYI, i am using Jenkins version 2.222.4

Jenkins installation issue through Ansible playbook

I have written ansible playbook to install cloudbees jenkins in our production VM's. While running ansible playbook for the first time, it got successful but jenkins not up and running and same playbook running in second time jenkins up and running fine.
I have manually downloaded jenkins.war(2.138.x) and moved to VM. While running ansible playbook for the first time it is executed successfully, but the jenkins is not up and running, so i went inside vm and checked jenkins home directory. It is only showing one folder i.e WAR, but while running the same playbook for the second time the jenkins is up on running and again i have logged into Vm and checked jenkins home directory. Now i can able to see all configuration files inside home directory.i have checked the logs what i have observed is first time while running the jvm lines is not taken. but while running second time i have observed some jvm related lines.But i have installed java and i set environment variables as well.
- hosts: all
become: true
become_user: user1
tasks:
- name: installing the jenkins
shell: nohup java -DJENKINS_HOME=/user1/jenkins -jar /user1/jenkins.war &
I am expecting the cloudbees jenkins installation for first time only, while running the Ansible-playbook
- hosts: all
become: true
become_user: user1
tasks:
- name: installing the jenkins
shell: cd /user1 ; nohup java -DJENKINS_HOME=/user1/jenkins -jar jenkins.war &
First change the current directory to your jenkins war file directory and then run the nohup command in remote server

Create Jenkins slave from command line

I have a script that create a VM then I need to add the new VM as a slave to existing master,
How can I do that from command line in windows and from the new VM ?
Create a VM (OS = WINDOWS)
Create a Node on jenkins server from command line using jenkins cli:
config.xml | ssh -l fmud -p %JNLP_PORT% %jenkins_IPADDRESS% create-node %TARGET_WIN_NODE_NAME%
Where Config.xml could be gathered from an existing slave with command:
ssh -l fmud -p %JNLP_PORT% %jenkins_IPADDRESS% get-node %TARGET_WIN_NODE_NAME%
Note: JNLP is needed for jenkins-CLI and could be configured in jenkins administrative page.
Also, you will have to change the config file with label and name etc.
Connect the windows slave as service: Download winsw.exe
Rename it to jenkins_slave.exe
Download slave.jar (http://yourserver:port/jnlpJars/agent.jar )
Download and configure jenkins-slave.xml
Download and configure jenkins-slave.exe.config
in cmd: jenkins_slave.exe install
jenkins_slave.exe start
If it is a java slave, that is simple to automate. Like it if you find it helping or ask more specific question otherwise.

How can I run docker-compose up as shell script by Jenkins

I am trying to run command docker-compose up -d as a build step of Jenkins, in "execute shell". Job fails and gives me following console log:
docker-compose up --build -d
Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Build step 'Execute shell' marked build as failure
Finished: FAILURE`
When I cd into jenkins workspace (/var/lib/jenkins/workspace/app/) and tried to run docker-compose up, at first I could get a normal build. Right now I get error in console: ERROR: Error processing tar file(archive/tar: invalid tar header):. Of course app builds and runs normally in home directory when invoked from console.
Docker is running on host. It is possible to run docker-compose by regular user. I did add jenkins user to docker group. I even tried following some asian tutorial from http://blog.csdn.net/qiyueqinglian/article/details/46559825 that made me change DOCKER_OPTS in default/docker, but after restarting docker service it was not running on port 4243, so I didn't understood translation or it is not working on ubuntu 16.04 (host system).
Jenkins is not running in container, it is casually installed on host, no VM no docker, nothing. I tried removing docker and jenkins completly from host (purge etc) and reinstalling, still the same errors.
Any ideas?
Hit this command as a root user and try again
usermod -aG docker jenkins

Updating Jenkins on Centos

I'm trying to update Jenkins on Centos7
When I run service Jenkins status command I can see that Jenkins is active.
When I try to connect to Jenkins using the browser I'm getting this message:
refused to connect to http://*****:8080.
I have followed the following steps but it's not working:
1) Run service Jenkins stop command.
2) Replaced Jenkins.war with the new one.
3) Run service Jenkins start command.
i update it using this command :
yum update jenkins
it's working well
This worked for me on RedHat distribution:
sudo service jenkins stop
yum update jenkins
sudo service jenkins start

Resources