area51/jenkins-slave
A Jenkins slave for building Java applications
The area51/jenkins-slave image contains a current Java build (it extends the area51/java:serverjre-8 image) suitable to be used as a Jenkins slave.
Usage
To run the slave you need to launch it, get it's IP address then configure jenkins to use it:
# docker run --name javaSlave area51/jenkins-slave # docker inspect --format '{{ .NetworkSettings.IPAddress }}' jenkins-slave 172.17.0.5
Here's an example with:
- Static IPv6 address set
- Uses a preconfigured docker bridge network called jenkinsNet
- Jenkins password to secret
- Maven will use a private Nexus 3 mirror on mymirror.example
- Will be able to deploy to maven using the user deployment and password secret
# docker run -d \ --restart=always \ --name javaSlave \ --hostname javaSlave \ --net=jenkinsNet \ --ip6=2001:DB8:1234:5678::2 \ -e JENKINS_PASSWORD=secret \ -e MAVEN_MIRROR=http://mymirror.example/repository/maven-public \ -e MAVEN_SNAPSHOT_USER=deployment \ -e MAVEN_SNAPSHOT_PASSWORD=secret \ area51/jenkins-slave
You would then configure it in Jenkins with [2001:DB8:1234:5678::2] as the ip address, jenkins as the ssh user and secret as the password.
Slave configuration
Then in jenkins, create a new ssh slave and enter the following details:
Field | Value | Description |
---|---|---|
Name | Java | Your name for this slave |
Description | Optional description for this slave | |
# of executors | 4 | The number of job executors you want to run in this slave |
Remote root directory | /opt/jenkins | The location to store the jobs whilst running. /opt/jenkins is configured in this container for you |
Labels | java | Labels for fixing specific jobs to this slave. You can choose what you want here, this is a suggestion. |
Usage | How much you want jenkins to use it. Usually the default Use this node as much as possible is fine here. | |
Launch method | Launch via ssh | We want ssh here |
You should now see: | ||
Host | 172.17.0.5 | The IP address from above. If you have made it static (advisable) then use that. If it's an IPv6 address then you need to put [ ] around the address |
Credentials | Select add and create a new entry. Unless you've changed it (see below) the user is jenkins and the password jenkins | |
Click advanced to show next fields then: | ||
JavaPath | /opt/jdk/bin/java | The path to the installed java binary within the container |
Environment Variables
You can configure the following environment variables:
Variable | Description |
---|---|
JENKINS_PASSWORD | You can set the password for the jenkins user with this variable. If you don't it defaults to jenkins e.g. --env JENKINS_PASSWORD=beeblebrox |
MAVEN_MIRROR | By default maven will use just the maven central repository. If you run your own local repository (i.e. Nexus or our area51/nexus image) then you can set this to the base url path to that mirror e.g. --env MAVEN_MIRROR=http://mymirror.example/repository/maven-public |
MAVEN_RELEASE_USER MAVEN_RELEASE_PASSWORD | Username and Password to use when deploying release artifacts to your repository. |
MAVEN_RELEASE_ID | Only valid if both MAVEN_RELEASE_USER & MAVEN_RELEASE_PASSWORD are defined this sets the id within settings.xml. If it's not defined then it defaults to releases |
MAVEN_SNAPSHOT_USER MAVEN_SNAPSHOT_PASSWORD | Username and Password to use when deploying snapshot artifacts to your repository. |
MAVEN_SNAPSHOT_ID | Only valid if both MAVEN_SNAPSHOT_USER & MAVEN_SNAPSHOT_PASSWORD are defined this sets the id within settings.xml. If it's not defined then it defaults to snapshots |
NO_SSH | If set to any value other than then this disables the built in sshd daemon but you must then provide a command to run instead otherwise the container will not start. |