mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 23:05:49 +00:00
Update Jenkinsfile
This commit is contained in:
parent
592b7338f9
commit
4c7c33d47f
1 changed files with 15 additions and 1 deletions
16
Jenkinsfile
vendored
16
Jenkinsfile
vendored
|
@ -1,7 +1,7 @@
|
|||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
DOCKER_CREDENTIALS_ID = 'dockerhub-credentials'
|
||||
DOCKER_CREDENTIALS_ID = 'dockerhub-credentials' // ID DockerHub
|
||||
}
|
||||
stages {
|
||||
stage('Checkstyle') {
|
||||
|
@ -35,9 +35,23 @@ pipeline {
|
|||
withCredentials([usernamePassword(credentialsId: "${DOCKER_CREDENTIALS_ID}", usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
|
||||
def repoName = env.BRANCH_NAME == 'main' ? 'main-jenkins' : 'mr-jenkins'
|
||||
def tag = env.GIT_COMMIT?.substring(0, 7) ?: 'latest'
|
||||
|
||||
// Build Docker image
|
||||
sh """
|
||||
docker login -u \$DOCKER_USERNAME --password \$DOCKER_PASSWORD
|
||||
docker build -t marijastopa/${repoName}:${tag} .
|
||||
"""
|
||||
|
||||
// Tag 'latest' for main branch
|
||||
if (env.BRANCH_NAME == 'main') {
|
||||
sh """
|
||||
docker tag marijastopa/${repoName}:${tag} marijastopa/${repoName}:latest
|
||||
docker push marijastopa/${repoName}:latest
|
||||
"""
|
||||
}
|
||||
|
||||
// Push SHA tag
|
||||
sh """
|
||||
docker push marijastopa/${repoName}:${tag}
|
||||
"""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue