| 1 |
pipeline { |
| 2 |
agent {label "docker"} |
| 3 |
options { |
| 4 |
buildDiscarder(logRotator(numToKeepStr: '32', daysToKeepStr: '14')) |
| 5 |
ansiColor('xterm') |
| 6 |
} |
| 7 |
parameters { |
| 8 |
booleanParam( |
| 9 |
name: 'REBUILD_IMAGE', |
| 10 |
defaultValue: false, |
| 11 |
description: 'Rebuild docker image? If the report script has changed, the image should be rebuilt.' |
| 12 |
) |
| 13 |
} |
| 14 |
stages { |
| 15 |
stage('Rebuild docker image') { |
| 16 |
when { |
| 17 |
beforeAgent true |
| 18 |
expression { return params.REBUILD_IMAGE } |
| 19 |
} |
| 20 |
steps { |
| 21 |
sh """ |
| 22 |
docker build \ |
| 23 |
-f dockerfile/report-jira-slack.dockerfile \ |
| 24 |
-t ${env.MEGA_INTERNAL_DOCKER_REGISTRY}:8443/report-jira-slack-sdk:latest \ |
| 25 |
. |
| 26 |
""" |
| 27 |
withCredentials([usernamePassword(credentialsId: 'artifactory-jenkins-docker', usernameVariable: 'ART_USER', passwordVariable: 'ART_PASS')]) { |
| 28 |
sh """ |
| 29 |
echo \$ART_PASS | docker login \ |
| 30 |
-u \$ART_USER \ |
| 31 |
--password-stdin \ |
| 32 |
${env.MEGA_INTERNAL_DOCKER_REGISTRY}:8443 |
| 33 |
docker push ${env.MEGA_INTERNAL_DOCKER_REGISTRY}:8443/report-jira-slack-sdk:latest |
| 34 |
""" |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
stage('Run report'){ |
| 39 |
steps { |
| 40 |
withCredentials([usernamePassword(credentialsId: 'artifactory-jenkins-docker', usernameVariable: 'ART_USER', passwordVariable: 'ART_PASS')]) { |
| 41 |
sh """ |
| 42 |
echo \$ART_PASS | docker login \ |
| 43 |
-u \$ART_USER \ |
| 44 |
--password-stdin \ |
| 45 |
${env.MEGA_INTERNAL_DOCKER_REGISTRY}:8443 |
| 46 |
docker pull ${env.MEGA_INTERNAL_DOCKER_REGISTRY}:8443/report-jira-slack-sdk:latest |
| 47 |
""" |
| 48 |
} |
| 49 |
withCredentials([ |
| 50 |
string(credentialsId: 'SDK_JIRA_PERSONAL_ACCESS_TOKEN', variable: 'SDK_JIRA_PERSONAL_ACCESS_TOKEN'), |
| 51 |
string(credentialsId: 'SDK_SLACK_BOT_TOKEN', variable: 'SDK_SLACK_BOT_TOKEN') |
| 52 |
]){ |
| 53 |
// SDK report |
| 54 |
sh """ |
| 55 |
docker run \ |
| 56 |
--rm \ |
| 57 |
-e JIRA_PERSONAL_ACCESS_TOKEN=\${SDK_JIRA_PERSONAL_ACCESS_TOKEN} \ |
| 58 |
-e SLACK_BOT_TOKEN=\${SDK_SLACK_BOT_TOKEN} \ |
| 59 |
-e JIRA_URL=${env.JIRA_URL} \ |
| 60 |
-e JIRA_PROJECT_KEY=${env.SDK_JIRA_PROJECT_KEY} \ |
| 61 |
-e SLACK_CHANNEL=${env.SDK_SLACK_CHANNEL} \ |
| 62 |
${env.MEGA_INTERNAL_DOCKER_REGISTRY}:8443/report-jira-slack-sdk:latest |
| 63 |
""" |
| 64 |
// CHT report |
| 65 |
sh """ |
| 66 |
docker run \ |
| 67 |
--rm \ |
| 68 |
-e JIRA_PERSONAL_ACCESS_TOKEN=\${SDK_JIRA_PERSONAL_ACCESS_TOKEN} \ |
| 69 |
-e SLACK_BOT_TOKEN=\${SDK_SLACK_BOT_TOKEN} \ |
| 70 |
-e JIRA_URL=${env.JIRA_URL} \ |
| 71 |
-e JIRA_PROJECT_KEY=${env.CHT_JIRA_PROJECT_KEY} \ |
| 72 |
-e SLACK_CHANNEL=${env.CHT_SLACK_CHANNEL} \ |
| 73 |
${env.MEGA_INTERNAL_DOCKER_REGISTRY}:8443/report-jira-slack-sdk:latest |
| 74 |
""" |
| 75 |
} |
| 76 |
} |
| 77 |
post { |
| 78 |
always { |
| 79 |
deleteDir() |
| 80 |
sh """ |
| 81 |
docker rmi -f ${env.MEGA_INTERNAL_DOCKER_REGISTRY}:8443/report-jira-slack-sdk:latest |
| 82 |
""" |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
// vim: syntax=groovy tabstop=4 shiftwidth=4 |