|
@@ -15,6 +15,7 @@ pipeline {
|
|
|
DOCKER_CERT_PATH='/run/secrets/swarm'
|
|
|
DOCKER_HOST=''
|
|
|
DOCKER_REGISTRY=''
|
|
|
+ NEWTAG=''
|
|
|
}
|
|
|
parameters {
|
|
|
string(
|
|
@@ -56,19 +57,20 @@ pipeline {
|
|
|
error('Unknown cluster')
|
|
|
}
|
|
|
}
|
|
|
- echo "Docker ${DOCKER_HOST}, Registry ${DOCKER_REGISTRY}"
|
|
|
echo "Building ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}."
|
|
|
- sh "docker build --build-arg repo=${repo} --no-cache -t ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ."
|
|
|
+ sh "docker build --build-arg repo=${repo} --no-cache -t ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ."
|
|
|
+ script {
|
|
|
+ NEWTAG = sh script: "docker run --rm ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} rpm -q --qf %{VERSION}-%{RELEASE} ${PACKAGE_NAME} 2> /dev/null", returnStdout: true
|
|
|
+ NEWTAG = repo + "-" + NEWTAG + "_" + BUILD_NUMBER
|
|
|
+ echo "NEWTAG is $NEWTAG"
|
|
|
+ }
|
|
|
+ sh "docker tag ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
}
|
|
|
}
|
|
|
stage("Publish") {
|
|
|
steps {
|
|
|
- echo "Publishing ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}"
|
|
|
- sh "docker push ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}"
|
|
|
- script {
|
|
|
- sh "echo Building ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}."
|
|
|
- }
|
|
|
- error ("Emergency exit")
|
|
|
+ echo "Publishing ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
+ sh "docker push ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${NEWTAG}"
|
|
|
}
|
|
|
}
|
|
|
stage("Update") {
|
|
@@ -77,43 +79,12 @@ pipeline {
|
|
|
script {
|
|
|
for (String item : service_update.split()) {
|
|
|
try{
|
|
|
- echo "Updating $item"
|
|
|
- if (cluster == 'prod') {
|
|
|
- withEnv(["service_name=${item}"]) {
|
|
|
- sh '''export DOCKER_CERT_PATH=/run/secrets/swarm
|
|
|
- export DOCKER_HOST=tcp://${CLUSTER_PROD}:2376 DOCKER_TLS_VERIFY=1
|
|
|
- docker service update ${service_name} --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}
|
|
|
- '''
|
|
|
- }
|
|
|
- }
|
|
|
- if (cluster == 'dev') {
|
|
|
- withEnv(["service_name=${item}"]) {
|
|
|
- sh '''export DOCKER_CERT_PATH=/run/secrets/swarm
|
|
|
- export DOCKER_HOST=tcp://${CLUSTER_DEV}:2376 DOCKER_TLS_VERIFY=1
|
|
|
- docker service update ${service_name} --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}
|
|
|
- '''
|
|
|
- }
|
|
|
- }
|
|
|
+ sh "docker service update ${service_name} --image ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG}"
|
|
|
}
|
|
|
catch(err){
|
|
|
- echo "Recovering service $item"
|
|
|
- if (cluster == 'prod') {
|
|
|
- withEnv(["service_name=${item}"]) {
|
|
|
- sh '''export DOCKER_CERT_PATH=/run/secrets/swarm
|
|
|
- export DOCKER_HOST=tcp://${CLUSTER_PROD}:2376 DOCKER_TLS_VERIFY=1
|
|
|
- docker service rollback ${service_name}
|
|
|
- '''
|
|
|
- }
|
|
|
- }
|
|
|
- if (cluster == 'dev') {
|
|
|
- withEnv(["service_name=${item}"]) {
|
|
|
- sh '''export DOCKER_CERT_PATH=/run/secrets/swarm
|
|
|
- export DOCKER_HOST=tcp://${CLUSTER_DEV}:2376 DOCKER_TLS_VERIFY=1
|
|
|
- docker service rollback ${service_name}
|
|
|
- '''
|
|
|
- }
|
|
|
- }
|
|
|
- throw err
|
|
|
+ echo "Recovering service $item"
|
|
|
+ sh "docker service rollback ${service_name}"
|
|
|
+ throw err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -122,21 +93,21 @@ pipeline {
|
|
|
stage("Tagging"){
|
|
|
steps{
|
|
|
echo "Setting latest tag"
|
|
|
- sh '''docker tag ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER} ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:latest
|
|
|
- docker push ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:latest'''
|
|
|
+ sh """docker tag ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:${NEWTAG} ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:latest
|
|
|
+ docker push ${DOCKER_REGISTRY}/iru/${DOCKER_IMAGE}:latest"""
|
|
|
echo "Updating tag info in ${SWARM_GIT_NAME} repository"
|
|
|
withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) {
|
|
|
- sh '''GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
|
|
|
+ sh """GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
|
|
|
git clone ${SWARM_GIT_URL}
|
|
|
cd ${SWARM_GIT_NAME}
|
|
|
- echo -n ${repo}-${BUILD_NUMBER} > tags/${DOCKER_IMAGE}.version
|
|
|
+ echo -n ${NEWTAG} > tags/${DOCKER_IMAGE}.version
|
|
|
git add -A
|
|
|
git config --global user.email "${JENKINS_MAIL}"
|
|
|
git config --global user.name "Jenkins"
|
|
|
git commit -m 'Version update'
|
|
|
GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
|
|
|
git push origin master
|
|
|
- ls'''
|
|
|
+ ls"""
|
|
|
}
|
|
|
}
|
|
|
}
|