Live together in perfect harmony
docker pull jenkins/jenkins:lts
docker run --name myjenkins -p 8080:8080 -p 50000:50000 \
-v /var/jenkins_home jenkins/jenkins:lts
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
d5567ba0c53b43709e2daae0bf8e6fa9
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
During installation, logs provide a key for initial setup
Continue setup and install suggested plugins
Install Blue Ocean, Bitbucket, Jacoco, and Sonarqube scanner plugins
Restart Jenkins
Add a JDK
Manage Jenkins > Global Tools configuration
Jdk > Jdk installations
Name : jdk8
Install automatically : checked
Add a JDK
Run shell command
label : install open-jdk8
Command : `sudo apt-get --assume-yes install openjdk-8-jdk`
Tool Home : `/usr/bin`
Add a Maven Tool
Maven > Maven installations
Name : maven-3.5.3
Install automatically : checked
Install from Apache : 3.5.3
docker volume create --name bitbucketVolume
docker run -v bitbucketVolume:/var/atlassian/application-data/bitbucket \
--name="bitbucket" -d -p 7990:7990 -p 7999:7999 atlassian/bitbucket-server:5.5
docker pull sonarqube:lts
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube:lts
http://172.17.0.1:9000 (depending on your docker ip)
Generate a token
Generate a token
Generate a token
Generated maven command
mvn sonar:sonar \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=6470b64c0936e5e479b5c1504a8e547cf8a7351d
mvn sonar:sonar \
-Dsonar.host.url=http://172.17.0.1:9000 \
-Dsonar.login=6470b64c0936e5e479b5c1504a8e547cf8a7351d
Using docker IP
Jenkins configuration, use the generated token
docker start myjenkins
docker start bitbucket
docker start sonarqube
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.bouvier.marc</groupId>
<artifactId>pipeline-as-code</artifactId>
<version>1.0-SNAPSHOT</version>
<name>pipeline-as-code</name>
<description>A simple pipeline-as-code.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<skip.surefire.tests>${skipTests}</skip.surefire.tests>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<!-- skips surefire tests without skipping failsafe tests.
Property value seems to magically default to false -->
<skipTests>${skip.surefire.tests}</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
public class App
{
public static void main( String[] args )
{
System.out.println( printHelloWorld());
}
public static String printHelloWorld(){
return "Hello World!";
}
}
public class AppTest {
@Test
public void testApp() {
assertThat(
App.printHelloWorld(),
is(equalTo("Hello World!")));
}
}
public class AppIT {
@Test
public void testApp() {
assertThat(
App.printHelloWorld(),
is(equalTo("Hello World!")));
}
}
pipeline {
agent any
stages {
stage('Initialize') {
steps {
sh '''
echo "PATH = ${PATH}"
echo "M2_HOME = ${M2_HOME}"
'''
}
}
stage('Build') {
steps {
echo 'Building..'
sh 'mvn clean compile'
}
}
stage('Tests') {
parallel {
stage('Unit tests') {
steps {
echo 'Testing..'
sh 'mvn test'
}
post {
always {
junit '**/surefire-reports/**/*.xml'
}
}
}
stage('Integration test') {
steps {
echo 'Testing..'
sh 'mvn verify failsafe:integration-test -Dskip.surefire.tests=true'
}
post {
always {
junit '**/surefire-reports/**/*.xml'
}
}
}
}
}
stage('Jacoco') {
steps {
jacoco()
}
}
stage("Package"){
steps{
sh 'mvn package'
archiveArtifacts(artifacts: '**/target/*.jar', fingerprint: true)
}
}
stage('Sonar') {
steps {
sh '''mvn sonar:sonar \\
-Dsonar.host.url=http://172.17.0.1:9000 \\
-Dsonar.login=0309b3dc4d0ca5a4fc35d0f18428499c818616c6'''
}
}
stage('Deploy') {
steps {
echo 'Deploying...'
}
}
}
tools {
maven 'maven-3.5.3'
jdk 'jdk8'
}
}
Build status on branches...
... and Pull Requests!
Build the merged result of your Pull Request before it is merged
Based on Jenkinsfile configuration as code
Builds on each branch
Builds merged result of Pull Requests
Generates or update Jenkinsfile