What is the right way to add Maven and Ant to a Jenkins Docker container? - docker

I downloaded the jenkins/jenkins:lts image from docker hub which I got up and running on Ubuntu 16.04. The image doesn't seem to include Ant or Maven, and may also want to do builds against different versions of the jdk. I am wondering what is the right way to adress this - can I just run bash on the container and run apt-get or yum as the case may be to install extra stuff needed for my builds, or is there a better way?

Jenkins can automatically install Maven and Ant.
First, install the Ant Plugin by going to Manage jenkins > Manage Plugin > Available and install the Ant Plugin.
Next go to Manage jenkins > Global tool configuration then add Maven and Ant.
Once a build requires Maven or Ant, they will be downloaded and installed.

Installing your tools directly in the running container is probably a bad idea as changes won't persist. Instead, I see the following options:
Let jenkins manage your tools like proposed by yamenk
Clone the jenkinsci docker repository and build your custom jenkins image including build tools you need
Run build jobs in docker containers
I used option 3 with success just recently:
Run build jobs inside docker containers (look into Jenkins pipeline plugin, or just run it from a shell step)
Each build container has a single responsibility and provides all the tools your build environment needs
Support for different tools and versions is unlimited; new technologies can be added in no time

Another (more tricky) alternative is it to use Docker Containers for your tools.
I can recommend the following two articles:
https://jenkins.io/blog/2016/08/08/docker-pipeline-environments/
https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/

Related

Can't find Docker Plugin on Jenkins

I'm trying to build an image using docker.
Connecting with Jenkins, then moving to
Manage Jenkins > Plugins management, I don't found Docker plugin there.
Also, I tried Manage Jenkins > Global Tool Configuration, I can't see Docker Part as displayed bellow.
Could you please tell me what I missed ?.
Big thanks.
You can add that plugin using the download of docker-build-publish-1.3.2.hpi.
Then you have to restart Jenkins.
HTH
Download externally docker plugin which is .hpi file and place that file under /JENKINS_HOME/plugins folder
You could go to Manage Jenkins -> Manage Plugins -> search for docker in the search bar to the top right corner -> install docker.
You may choose to restart jenkins after the installation is complete. Once the docker plugin is fully installed, head over to Manage Jenkins -> Global Tool Configuration -> at the bottom you'll have docker available.

How to create a Dockerfile that installs git and jenkins?

Background info
I plan to create two containers.
Container 1 will have Jenkins and Git installed. The purpose of having Git installed with Jenkins is so I can retrieve my git repository in the "Select pipeline script from scm" section in a pipeline job. The container needs to have access to Git.
Container 2 will have all the dependencies for my .NET Windows application installed (MSBuild, Wix, Nuget, .NET frameworks, etc.).
Challenge
For container 1, how do I install Git if my base image is jenkins:latest. I tried using apt-get and apk add. Those obviously don't work since my base image is not ubuntu or alpine...
I expect downloading the packages in container 2 will be a lot easier since I would just use the ubuntu base image.
Looking at Jenkins's dockerfile, it looks like git is pre-installed for you.
For challenge 2, since you're using a ubuntu image, it's just the same as installing .Net dependencies on a ubuntu machine.

Update jenkins war on one machine and then move it to another one: possible?

I have a machine with blocked outgoing connections so it is not possible to update jenkins nor install the plugins I need for my work.
My idea is the following: I download the jenkins .war on my personal laptop and complete the installation + the plugin download.
Then I just move this .war to the machine where I need jenkins to be up and running.
Is it possible? Where are the plugins/updated data stored?
Also, would it be a problem the fact that my laptop has windows as os, while the destination machine is a linux RHEL?
Your solution sounds crazy :D
This could be help you:
Update Jenkins war
If you have shell access with root privilege, there is a manual way.
Download latest war file inside your linux, using wget , curl or just upload it using winscp from your windows.
Stop jenkins
Backup EVERYTHING: linux snapshot, jenkins workspace, jenkins war file, etc
Replace the old war with new war
Start jenkins
Detailed steps in this webs:
https://mohitgoyal.co/2017/02/15/upgrade-jenkins-server-to-a-new-version/
https://www.thegeekstuff.com/2016/06/upgrade-jenkins-and-plugins/
Plugin
Jenkins has an option to install plugins called Manage Plugins
This offer two options :
(1) Install plugins using available option
For official and compatible plugins, suggested by Jenkins :
(2) Install plugins using upload option
For custom plugins or when is not available on official repositories:

Docker : Change open Jdk to oracle Jdk in Jenkins image

I am very new to docker and I am trying to run a Jenkins image. I pulled the image from the repository and now am able to run it using the command
docker run -p 8080:8080 jenkinsci/jenkins
By default it uses openjdk version 1.8. I would like to use oracle Jdk instead of openjdk. How could I change this? Thanks in advance.
If you really want to use this image and change the jdk, you will have to build your own image from this one, install oraclejdk, setup Jenkins to use this jdk (like environment variables etc), but it is not a clean way, imho.
The best practice would be to build your own image from a oraclejdk Docker image and setup Jenkins on it.
You should look at other Dockerfiles to do this.
Oracle provides a bunch of docker images on github : https://github.com/oracle/docker-images
You should check your other requirements as well (OS, etc.)

Is there a way to install the ios-universal-framework on a cloudbees spawned Jenkins slave?

Using a Master Jenkins on premises, and the cloudbees plugin, I am able to kick off iOS builds to a cloud bees instance. It's pretty sweet.
My IOS developers require cloning the ios-universal-framework repo, and then running an install.sh script contained within that repo. Everything works fine until the script issues a "sudo" command to copy files into the directory
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Specifications"
The cp command needs sudo privileges. I'm thinking this is not possible but since I'm on the free trial plan, this is where I can find support. Thanks to all for reading.
Tony

Resources