Skip to content

Commit 1bc8f90

Browse files
committed
chore: semver versioning of container tags
1 parent f375edc commit 1bc8f90

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

jenkins/webapp.groovy

+21-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,31 @@ pipelineJob('build-and-push-webapp') {
1616
credentialsId: 'github-pat')
1717
}
1818
}
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+
}
1935
stage('Build and push Docker Image using buildx') {
2036
steps {
2137
sh 'echo DOCKER_PASSWORD | docker login -u DOCKER_USERNAME --password-stdin'
38+
// Use the determined version for tagging
39+
def imageTag = "${env.NEW_VERSION}"
2240
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'
2644
}
2745
}
2846
}

0 commit comments

Comments
 (0)