forked from jenkins-docs/simple-java-maven-app
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
82 lines (80 loc) · 3.26 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
pipeline {
agent none
stages {
stage('Dredd API testing') {
agent any
steps {
// sh './jenkins/scripts/run-dredd.sh'
sh 'dredd definition_test.yaml http://31.171.247.162:50003'
}
}
}
}
/*
pipeline {
// Mandatory to use per-stage agents
agent none
stages {
stage('Build - test') {
// Ya no necesito todo esto no? Puedo usar una imagen estandar.
agent {
docker {
image 'maven:3.5.3-jdk-8'
// TODO esta caché debería ser por workspace, no por usuario, dos builds maven compartirían cache aquí!
//args '-u 0 -v ~/.m2:~/.m2 -v /var/run/docker.sock:/var/run/docker.sock'
// TODO cache is not working because /root is not writable by cloudsigma (1000) user that jenkins is using to connecto to the container
// -u 0 works but arises other problems like asigning
args '-v "$HOME/.m2":/root/.m2'
}
}
steps {
sh 'mvn -B -DskipTests clean package'
// Lets make the JAR available from the artifacts tab in Jenkins
archiveArtifacts 'target/*.jar'
// Run the tests (we don't use a different stage for improving the performance, another stage would mean another agent)
sh 'mvn test'
}
// TODO stop if test fails!
post {
always {
// Record the jUnit test
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Image creation') {
agent any
steps {
// The Dockerfile.artifact copies the code into the image and run the jar generation.
echo 'Creating the image...'
// This will search for a Dockerfile.artifact in the working directory and build the image to the local repository
sh "docker build -t \"ditas/simple-java-maven-app:latest\" -f Dockerfile.artifact ."
echo "Done"
echo 'Retrieving Docker Hub password from /opt/ditas-docker-hub.passwd...'
// Get the password from a file. This reads the file from the host, not the container. Slaves already have the password in there.
script {
password = readFile '/opt/ditas-docker-hub.passwd'
}
echo "Done"
echo 'Login to Docker Hub as ditasgeneric...'
sh "docker login -u ditasgeneric -p ${password}"
echo "Done"
echo "Pushing the image ditas/simple-java-maven-app:latest..."
sh "docker push ditas/simple-java-maven-app:latest"
echo "Done"
}
}
stage('Image deploy') {
// TO-DO avoid downloading the source from git again, not neccessary
agent any
steps {
echo 'to-do'
// Staging environment: 31.171.247.162
// Private key for ssh: /opt/keypairs/ditas-testbed-keypair.pem
// Call the deployment script
sh './jenkins/scripts/deploy-staging.sh'
}
}
}
}
*/