Updating Jenkins on Centos - jenkins

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

Related

Jenkins CI deploying docker image on Heroku

I have a Jenkins CI and use it to build (mvn) and containerize (docker) my app using Jenkins scripted pipeline. Lastly, I want to deploy my container to Heroku dyno (I have already created an app).
I have followed this documentation https://devcenter.heroku.com/articles/container-registry-and-runtime and have been successfully pushed my docker image to registry.heroku.com/sunset-sailing-4049/web.
The issue is since this announcement https://devcenter.heroku.com/changelog-items/1426 I now need to explicitly execute "heroku container:release web" in order to get my docker container running from registry to app dyno. This is where I am royally stuck. See my below issues:
Heroku is not recognized by Jenkins. (My Jenkins is running on ec2, I have installed heroku toolbelt as ec2-user user. But Jenkins throws error: heroku: command not found). How do I resolve this issue?
How to do "heroku login" from Jenkins, since the login command prompts for browser login. I have added ssh key but I do not know how to use it from the command line, hence Jenkins "shell script"
The only other way I could think of is deploying via heroku pipeline using a dummy git repo onto which Jenkins will upload the source code on a successful build.
Would really appreciate your help solving the above 2 issues.
Thanks in Advance.
You need install heroku as user under which jenkins is running. Or if you installed it globally it may be not in PATH of user under which jenkins is running.
There are multiple options for setting PATH:
Set for specific command.
If your job is pipeline just wrap heroku command in withEnv closure:
withEnv(['PATH+HEROKU=/use/local/bin/']) {
your heroku command here
}
Set path for jenkins slave: go to [Manage Jenkins] -> [Manage Nodes], configure your node and set Environment variable PATH to $PATH:/use/local/bin/. This way all jobs running on slave will get environment variable injected.
For automated cli interactions heroku supports API tokens. You can either put it in ~/.netrc on build machine or supply as environment variable (see here).
(writing here incase someone is facing the same scenario)
ok I took #vladimir's suggestion and did the below:
Heroku command (for jenkins running on ec2):
The below command is needed to push a built docker image to heroku via jenkins/or other ci/cd tool; Because of a recent change (https://devcenter.heroku.com/changelog-items/1426) pushing to heroku registry isn't sufficient any longer. In order to execute the below command you need to install heroku toolbelt.
heroku container:release web
Install snap on amazon linux like below:
follow instruction to enable epel https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/add-repositories.html
Then Modify /etc/yum.repos.d/epel.repo. Under the section marked [epel] , change enabled=0 to enabled=1.
Then do
sudo yum install epel-release
sudo yum install yum-plugin-copr
sudo yum copr enable ngompa/snapcore-el7
sudo yum -y install snapd
sudo systemctl enable --now snapd.socket
Then install heroku toolbelt:
sudo snap install --classic heroku
Deploying to docker image to heroku:
In Jenkins scripted pipeline:
withCredentials([string(credentialsId: 'heroku-api-cred', variable: 'herokuRegistryApiCred')]) {
sh "docker login -u email#example.com -p ${herokuRegistryApiCred} registry.heroku.com"
}
// Tag docker img (in my case it was an image in dockerhub)
sh "docker tag dockerhubusername/pvtreponame:${imageTag} registry.heroku.com/your_app_name/release_type[ie>web]"
sh "docker push registry.heroku.com/your_app_name/web"
sh "/usr/local/bin/heroku container:release web --app=your_app_name"
sh "docker logout registry.heroku.com"
In order to run the app inside docker (in my case it was java) I had to add the below line (otherwise it was crashing because 1. tell app about heroku's port binding. 2. tell web process to run command. The ENTRYPOINT ["java","-jar","my_spring_boot_app-0.0.1-SNAPSHOT.jar"] does not work on heroku.):
CMD ["web", "java $JAVA_OPTS -Dserver.port=$PORT -jar /usr/app/my_spring_boot_app-0.0.1-SNAPSHOT.jar"]

Getting issue with Jenkins running as container, when executing Docker command for build images

Jenkins Docker Problem
Hello Everyone,
I installed DockerTool on Windows7. And running Jenkins in container(http://192.168.99.100:8080), and try build image via freestyle project for a POC. Seems my Jenkins is not able to execute docker command, but getting below error on build : -
"/tmp/jenkins4044405517350577133.sh: 2: /tmp/jenkins4044405517350577133.sh: docker: not found"
I have configured, Docker as Cloud in Jenkins->Configuration, but 'Docker Host URI' as tcp://192.168.99.100:2376 is not being connected, and keep running infinitely.
This value (tcp://192.168.99.100:2376), I get from executing command (docker-machine env) for DOCKER_HOST key.
command output docker-machine env
Please help me out!!!

Jenkins pipeline issue with Docker

When I was trying to run a Jenkins pipeline project, it failed giving this message under the "docker pull node:6-alpine":
<.jenkins/workspace/simple-node-js-react-npm-app#tmp/durable-431710c5/script.sh: line 2: docker: command not found
script returned exit code 127>
I have no idea what's going on here, and I couldn't access the directory mentioned in the error. I am pretty new to Jenkins.
As mentioned here, using the JENKINS Docker Plugin or JENKINS Docker Pipeline Plugin would not be enough to allow a node to use docker.
You still need to install docker on the node itself.
Please follow below steps:
Install the docker engine (yum install docker) on server where Jenkins is running.
Verify docker is installed: run command which docker.
Click on Jenkins manage plugin and install docker plugin.

How to create automatic docker image after successful build of Jenkins?

I want to create a automatic docker image through Jenkins once build got success.
I tried by providing docker commands in execute shell but throwing command not found error.If this is not right way how to achieve this in Windows 10.
Error:
................
................
12 passing (81ms)
+ docker build -t snapshot .
C:\WINDOWS\TEMP\jenkins6038297422360146327.sh: line 4: docker: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Even after installing docker inside jenkins it is not picking my docker url
Docker inside jenkins
Complete error of Docker URL
Created a new vm with TLS false:
docker-machine create -d virtualbox --engine-opt tlsverify=false node2
to check TLS is made false i ran below command
docker-machine env node2
here DOCKER_TLS_VERIFY = "1",however in the documentation it is mentioned DOCKER_TLS_VERIFY = "0" should be zero whether my machine now TLS enabled or not how can i confirm my machine is TLS false??
The shell you configured in your Jenkins job is executed by Jenkins executor on Jenkins machine(or Jenkins Slave machine if you're using Jenkins the Master-Slave way), so whatever command you would like to use, it must be installed correctly and in the PATH of the target machine, just like you execute command on terminal manually.
So the error message is self-explained now:
C:\WINDOWS\TEMP\jenkins6038297422360146327.sh: line 4: docker: command not found
which means you have not installed docker on your Jenkins machine, you need to install and configure it firstly.
Additionally, you may want to have a look at Docker build step plugin for Jenkins.
install docker on jenkins. Jenkins does not know about docker.
If you don't need to run Docker on the same server than Jenkins I found that downloading a Docker Client was better than using the Jenkins Plugin.
You can find the latest version here: https://download.docker.com/win/static/stable/x86_64/
Then just call the docker command with --host 192.168.99.100. It should work and build the image on the Docker Server 192.168.99.100

Calling docker commands from jenkins job as step running outside docker VM

I want to run a docker image create command from a Jenkins job which is running native on my machine with VM running Docker.
I've installed docker build step plugin and in manage Jenkins page command fails when I try to configure docker using url and version, it says:
Test Connection Something went wrong, cannot connect to
http://192.168.99.100:2376, cause: null
I've got this docker url from the docker-machine env command.
In the version field, I tried both REST API version and Docker version, but no success.
Is it possible to call Docker from outside the docker VM and from a Jenkins job? If yes how to configure it in Jenkins?

Resources