Compare commits
2 Commits
5ce61d2f9c
...
bcc46710cb
| Author | SHA1 | Date | |
|---|---|---|---|
| bcc46710cb | |||
| 7bc625c53f |
52
DockerPipelinePluginJenkinsfile
Normal file
52
DockerPipelinePluginJenkinsfile
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// 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 {
|
||||||
|
DOCKER_HUB_USER='guillemhs'
|
||||||
|
IMAGE_NAME="${DOCKER_HUB_USER}/the-example-app-20260302"
|
||||||
|
REGISTRY_CRED_ID='docker-credentials'
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
// Get some code from a GIT repository
|
||||||
|
git 'https://git.agile611.com/Agile611/the-example-app-nodejs.git'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Docker Build') {
|
||||||
|
steps {
|
||||||
|
script{
|
||||||
|
echo "Build image ..."
|
||||||
|
docker.build("${IMAGE_NAME}:${env.BUILD_NUMBER}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Docker Push')
|
||||||
|
{
|
||||||
|
steps{
|
||||||
|
script{
|
||||||
|
docker.withRegistry('',REGISTRY_CRED_ID){
|
||||||
|
def app = docker.image("${IMAGE_NAME}:${env.BUILD_NUMBER}")
|
||||||
|
|
||||||
|
echo "Pushing image to Docker Hub ..."
|
||||||
|
app.push("${env.BUILD_NUMBER}")
|
||||||
|
app.push("latest")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post{
|
||||||
|
always{
|
||||||
|
cleanWs()
|
||||||
|
sh "docker rmi ${IMAGE_NAME}:${env.BUILD_NUMBER} || true"
|
||||||
|
sh "docker rmi ${IMAGE_NAME}:latest || true"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user