Also tag as latest
This commit is contained in:
parent
0d4706105d
commit
f02cace731
1 changed files with 8 additions and 2 deletions
10
Jenkinsfile
vendored
10
Jenkinsfile
vendored
|
|
@ -44,18 +44,24 @@ pipeline {
|
|||
stage('Build & Push Docker Image') {
|
||||
when {
|
||||
expression {
|
||||
return env.ref?.startsWith('refs/tags/') && env.GIT_COMMIT && env.GIT_COMMIT != ""
|
||||
return env.ref?.startsWith('refs/tags/') && env.after !=~ /^0{40}$/
|
||||
}
|
||||
}
|
||||
steps {
|
||||
script {
|
||||
def tagName = env.ref?.replaceFirst(/^refs\/tags\//, '')
|
||||
sh "docker build -t $IMAGE_NAME:${tagName} -f docker/Dockerfile ."
|
||||
echo "Building image for tag: ${tagName}"
|
||||
|
||||
// Build both the tag and latest
|
||||
sh """
|
||||
docker build -t $IMAGE_NAME:${tagName} -t $IMAGE_NAME:latest -f docker/Dockerfile .
|
||||
"""
|
||||
|
||||
withCredentials([usernamePassword(credentialsId: "$DOCKER_CREDENTIALS_ID", usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
||||
sh """
|
||||
echo "$PASSWORD" | docker login $REGISTRY -u "$USERNAME" --password-stdin
|
||||
docker push $IMAGE_NAME:${tagName}
|
||||
docker push $IMAGE_NAME:latest
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue