Files
startusingjenkins/BuildJenkinsfileAgentAlpine

52 lines
1.6 KiB
Plaintext

// 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}/jenkins-alpine-agent"
REGISTRY_CRED_ID='docker-credentials'
}
stages {
stage('Checkout') {
steps {
// Get some code from a GIT repository
git branch: 'main', url: 'https://git.agile611.com/Agile611/startusingjenkins.git'
}
}
stage('Docker Build') {
steps {
script{
echo "Build image ..."
docker.build("${IMAGE_NAME}:${env.BUILD_NUMBER}","-f DockerfileAgentAlpine .")
}
}
}
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"
}
}
}