Step 6 - Promotion
Instead of rebuilding for every environment, we "promote" the immutable artifact from one repository to another.
Jenkinsfile¶
Here is the Jenkinsfile for this step. Source code: 30-06-Jenkinsfile-docker-promotion-build-info.
import groovy.json.JsonOutput
pipeline {
agent any
options {
disableConcurrentBuilds()
disableResume()
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
}
parameters {
choice(name: 'TARGET_REPOSITORY', choices: ['qa', 'prod'], description: 'Jfrog target repository for promotion')
string(name: 'BUILD_NUMBER', defaultValue: '1.0', description: 'Jfrog Build Info Build Number')
}
environment {
ARTIFACTORY_URL = "https://vigneshsweekaran2.jfrog.io"
BUILD_NAME = "hello-world-java"
ARTIFACTORY_CREDENTIAL_ID = "jfrog-credential"
}
stages {
stage ("Promotion") {
steps {
script {
def sourecRepository = "dev"
if ("${params.TARGET_REPOSITORY}" == "prod") {
sourecRepository = "qa"
}
def promotionConfig = JsonOutput.toJson([
status: "promoting",
sourceRepo: "docker-helloworld-${sourecRepository}-local",
targetRepo: "docker-helloworld-${params.TARGET_REPOSITORY}-local",
copy: true,
failFast: true
])
withCredentials([usernamePassword(credentialsId: "${ARTIFACTORY_CREDENTIAL_ID}", usernameVariable: 'ARTIFACTORY_USERNAME', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
sh """
curl -u${ARTIFACTORY_USERNAME}:${ARTIFACTORY_PASSWORD} -X POST ${ARTIFACTORY_URL}/artifactory/api/build/promote/${BUILD_NAME}/${params.BUILD_NUMBER} -H \"Content-Type: application/json\" --data '${promotionConfig}'
"""
}
}
}
}
}
post {
always {
deleteDir()
}
}
}
Detailed Explanation¶
Logic for Promotion¶
The script dynamically calculates the sourceRepo based on the requested TARGET_REPOSITORY.
- If promoting to QA, it pulls from Dev.
- If promoting to Prod, it pulls from QA.
This ensures a strict linear promotion path: Dev -> QA -> Prod.
JSON payload¶
We verify the payload structure before sending it:
- copy: true: Copies the artifact (keeping the original in source). If set to false, it moves it.
- status: "promoting": A status label added to the build info.
Important Tips¶
Important
This job uses the Build Info (Build Name and Build Number) to find the artifacts, not the Docker tag directly. This is why publishing build info in the previous step was mandatory.
Next Step: SonarQube Integration
Quick Quiz¶
Quick Quiz¶
What is "Artifact Promotion"?
Why is promoting an artifact better than rebuilding it?
Which HTTP method is typically used with the Artifactory Promote API?
📬 DevopsPilot Weekly — Learn DevOps, Cloud & Gen AI the simple way.
👉 Subscribe here