Changes in Docker Agent

This commit is contained in:
2026-04-15 12:02:59 +02:00
parent 91f37345ed
commit b7f72d9dbf
3 changed files with 19 additions and 11 deletions

View File

@@ -11,19 +11,23 @@ pipeline {
DOCKER_HUB_USER='guillemhs'
IMAGE_NAME="${DOCKER_HUB_USER}/jenkins-alpine-agent"
REGISTRY_CRED_ID='docker-credentials'
// 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()
TAG="${DATA}.${env.BUILD_NUMBER}"
}
stages {
stage('Checkout') {
steps {
// Get some code from a GIT repository
git branch: 'main', url: 'https://git.agile611.com/Agile611/startusingjenkins.git'
checkout scm
}
}
stage('Docker Build') {
steps {
script{
echo "Build image ..."
docker.build("${IMAGE_NAME}:${env.BUILD_NUMBER}","-f DockerfileAgentAlpine .")
docker.build("${IMAGE_NAME}:${TAG}","-f DockerfileAgentAlpine .")
}
}
}
@@ -32,10 +36,10 @@ pipeline {
steps{
script{
docker.withRegistry('',REGISTRY_CRED_ID){
def app = docker.image("${IMAGE_NAME}:${env.BUILD_NUMBER}")
def app = docker.image("${IMAGE_NAME}:${TAG}")
echo "Pushing image to Docker Hub ..."
app.push("${env.BUILD_NUMBER}")
app.push("${TAG}")
app.push("latest")
}
}
@@ -45,7 +49,7 @@ pipeline {
post{
always{
//cleanWs()
sh "docker rmi ${IMAGE_NAME}:${env.BUILD_NUMBER} || true"
sh "docker rmi ${IMAGE_NAME}:${TAG} || true"
sh "docker rmi ${IMAGE_NAME}:latest || true"
}
}