Docker Pipeline plugin Jenkinsfile
This commit is contained in:
49
DockerPipelinePluginJenkinsfile
Normal file
49
DockerPipelinePluginJenkinsfile
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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