Compare commits
5 Commits
5ce61d2f9c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b859a55d35 | |||
| 379155e012 | |||
| 95c277d7df | |||
| bcc46710cb | |||
| 7bc625c53f |
55
DockerPipelinePluginJenkinsfile
Normal file
55
DockerPipelinePluginJenkinsfile
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
// You need a valid credentials for Docker Hub
|
||||||
|
// You need https://plugins.jenkins.io/docker-workflow/ on your jenkins instance
|
||||||
|
|
||||||
|
pipeline {
|
||||||
|
agent {
|
||||||
|
node {
|
||||||
|
label 'docker' //Agent needs to have Docker Engine installed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
environment {
|
||||||
|
// Executem una comanda shell per obtenir la data actual i la guardem com a variable
|
||||||
|
DATA = sh(returnStdout: true, script: 'date +%Y.%m.%d').trim()
|
||||||
|
DOCKER_HUB_USER='guillemhs'
|
||||||
|
IMAGE_NAME="${DOCKER_HUB_USER}/the-example-app-nodejs"
|
||||||
|
REGISTRY_CRED_ID='docker-credentials'
|
||||||
|
TAG="${DATA}.${env.BUILD_NUMBER}"
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
// Get some code from the sane repository
|
||||||
|
checkout scm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Docker Build') {
|
||||||
|
steps {
|
||||||
|
script{
|
||||||
|
echo "Build image ..."
|
||||||
|
docker.build("${IMAGE_NAME}:${TAG}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Docker Push')
|
||||||
|
{
|
||||||
|
steps{
|
||||||
|
script{
|
||||||
|
docker.withRegistry('',REGISTRY_CRED_ID){
|
||||||
|
def app = docker.image("${IMAGE_NAME}:${TAG}")
|
||||||
|
|
||||||
|
echo "Pushing image to Docker Hub ..."
|
||||||
|
app.push("${TAG}")
|
||||||
|
app.push("latest")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post{
|
||||||
|
always{
|
||||||
|
cleanWs()
|
||||||
|
sh "docker rmi ${IMAGE_NAME}:${TAG} || true"
|
||||||
|
sh "docker rmi ${IMAGE_NAME}:latest || true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -79,3 +79,8 @@ Step 4: Push your image to the Docker hub
|
|||||||
docker push yourhubusername/verse_gapminder:firsttry
|
docker push yourhubusername/verse_gapminder:firsttry
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This repository is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License (CC BY-SA 4.0).
|
||||||
|
For details, see https://creativecommons.org/licenses/by-sa/4.0/.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user