@@ -16,13 +16,31 @@ pipelineJob('build-and-push-webapp') {
16
16
credentialsId: 'github-pat')
17
17
}
18
18
}
19
+ stage('Determine Version') {
20
+ steps {
21
+ // Setup Git configuration
22
+ sh 'git config --global user.email "jenkins@jenkins.hemanthnvd.com"'
23
+ sh 'git config --global user.name "Jenkins CI"'
24
+ // Use semantic-release to determine the next version
25
+ def releaseOutput = sh(script: 'npx semantic-release --dry-run --json', returnStdout: true).trim()
26
+ def versionLine = releaseOutput.find(/Published release (\d +\.\d +\.\d +) on default channel/)
27
+ if (versionLine) {
28
+ env.NEW_VERSION = (versionLine =~ /(\d +\.\d +\.\d +)/)[0][0]
29
+ echo "Determined new version: v${ env.NEW_VERSION} "
30
+ } else {
31
+ error "Failed to determine the new version from semantic-release."
32
+ }
33
+ }
34
+ }
19
35
stage('Build and push Docker Image using buildx') {
20
36
steps {
21
37
sh 'echo DOCKER_PASSWORD | docker login -u DOCKER_USERNAME --password-stdin'
38
+ // Use the determined version for tagging
39
+ def imageTag = "${ env.NEW_VERSION} "
22
40
sh 'docker buildx create --use'
23
- sh 'docker buildx build --platform linux/amd64,linux/arm64 -t DOCKER_USERNAME/cve-processor:latest -f Dockerfile.cve-processor --push .'
24
- sh 'docker buildx build --platform linux/amd64,linux/arm64 -t DOCKER_USERNAME/db-migration:latest -f Dockerfile.db-migration --push .'
25
- sh 'docker logout'
41
+ sh 'docker buildx build --platform linux/amd64,linux/arm64 -t DOCKER_USERNAME/cve-processor:${ imageTag } -f Dockerfile.cve-processor --push .'
42
+ sh 'docker buildx build --platform linux/amd64,linux/arm64 -t DOCKER_USERNAME/db-migration:${ imageTag } -f Dockerfile.db-migration --push .'
43
+ sh 'docker logout'
26
44
}
27
45
}
28
46
}
0 commit comments