From 47a2da26c70a8142cf244f72e967cfbbf18038ce Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Thu, 19 Dec 2019 16:27:17 -0500 Subject: [PATCH 1/5] Use `DOCKER_REGISTRY` as secret --- Jenkinsfile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index eaa6237..0c1f3d0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,6 @@ pipeline { SERVICE = 'auto-semver' GITHUB_KEY = 'rbn-ops github' GITHUB_URL = 'git@github.com:RightBrain-Networks/auto-semver.git' - DOCKER_REGISTRY = '356438515751.dkr.ecr.us-east-1.amazonaws.com' //Image tag to use for self-versioning @@ -18,7 +17,9 @@ pipeline { //Runs versioning in docker container stage('Self Version') { steps { - runAutoSemver("${DOCKER_REGISTRY}/auto-semver:${SELF_SEMVER_TAG}") + withCredentials( [secret( credentialsId: 'RbnDockerRegistry', secretVariable: 'DOCKER_REGISTRY')]) { + runAutoSemver("${DOCKER_REGISTRY}/auto-semver:${SELF_SEMVER_TAG}") + } } post{ // Update Git with status of version stage. @@ -35,8 +36,10 @@ pipeline { echo "Building ${env.SERVICE} docker image" - // Docker build flags are set via the getDockerBuildFlags() shared library. - sh "docker build ${getDockerBuildFlags()} -t ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ." + withCredentials( [secret( credentialsId: 'RbnDockerRegistry', secretVariable: 'DOCKER_REGISTRY')]) { + // Docker build flags are set via the getDockerBuildFlags() shared library. + sh "docker build ${getDockerBuildFlags()} -t ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ." + } sh "python setup.py sdist" } @@ -54,6 +57,7 @@ pipeline { { steps { withEcr { + withCredentials( [secret( credentialsId: 'RbnDockerRegistry', secretVariable: 'DOCKER_REGISTRY')]) { sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION}" script { @@ -63,6 +67,7 @@ pipeline { sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:latest" } } + } } sh "aws s3 cp `ls -t ./dist/semver-* | head -1` s3://rbn-ops-pkg-us-east-1/${env.SERVICE}/${env.SERVICE}-${env.VERSION}.tar.gz" From 5f20bcf0beb2acf0fe29a947ecc343aa63b22212 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Thu, 19 Dec 2019 16:37:22 -0500 Subject: [PATCH 2/5] Update withCredentials --- Jenkinsfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0c1f3d0..80e2f46 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline { //Runs versioning in docker container stage('Self Version') { steps { - withCredentials( [secret( credentialsId: 'RbnDockerRegistry', secretVariable: 'DOCKER_REGISTRY')]) { + withCredentials([string(credentialsId: 'RbnDockerRegistry', variable: 'DOCKER_REGISTRY')]) { runAutoSemver("${DOCKER_REGISTRY}/auto-semver:${SELF_SEMVER_TAG}") } } @@ -36,9 +36,9 @@ pipeline { echo "Building ${env.SERVICE} docker image" - withCredentials( [secret( credentialsId: 'RbnDockerRegistry', secretVariable: 'DOCKER_REGISTRY')]) { + withCredentials([string(credentialsId: 'RbnDockerRegistry', variable: 'DOCKER_REGISTRY')]) { // Docker build flags are set via the getDockerBuildFlags() shared library. - sh "docker build ${getDockerBuildFlags()} -t ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ." + sh "docker build ${getDockerBuildFlags()} -t ${DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ." } sh "python setup.py sdist" @@ -57,14 +57,14 @@ pipeline { { steps { withEcr { - withCredentials( [secret( credentialsId: 'RbnDockerRegistry', secretVariable: 'DOCKER_REGISTRY')]) { - sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION}" + withCredentials([string(credentialsId: 'RbnDockerRegistry', variable: 'DOCKER_REGISTRY')]) { + sh "docker push ${DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION}" script { if("${env.BRANCH_NAME}" == "develop") { - sh "docker tag ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ${env.DOCKER_REGISTRY}/${env.SERVICE}:latest" - sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:latest" + sh "docker tag ${DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ${DOCKER_REGISTRY}/${env.SERVICE}:latest" + sh "docker push ${DOCKER_REGISTRY}/${env.SERVICE}:latest" } } } From 57411e6a4649013ddc9747a2108ff765b2314803 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Thu, 19 Dec 2019 16:46:33 -0500 Subject: [PATCH 3/5] Reformat --- Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 80e2f46..1ae1f86 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,10 +5,8 @@ pipeline { agent any environment { SERVICE = 'auto-semver' - GITHUB_KEY = 'rbn-ops github' GITHUB_URL = 'git@github.com:RightBrain-Networks/auto-semver.git' - //Image tag to use for self-versioning SELF_SEMVER_TAG = "develop" @@ -86,7 +84,7 @@ pipeline { stage('Push Version and Tag') { steps { echo "The current branch is ${env.BRANCH_NAME}." - gitPushTags(env.GITHUB_KEY) + gitPushTags('rbn-ops github') } } } From 6b4568a2beb96a42d565032f5b1d5e6511eefe62 Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Thu, 19 Dec 2019 16:57:03 -0500 Subject: [PATCH 4/5] credentials environment variable --- Jenkinsfile | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1ae1f86..3686b0a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ pipeline { environment { SERVICE = 'auto-semver' GITHUB_URL = 'git@github.com:RightBrain-Networks/auto-semver.git' - + env.DOCKER_REGISTRY = credentials('RbnDockerRegistry') //Image tag to use for self-versioning SELF_SEMVER_TAG = "develop" @@ -15,9 +15,7 @@ pipeline { //Runs versioning in docker container stage('Self Version') { steps { - withCredentials([string(credentialsId: 'RbnDockerRegistry', variable: 'DOCKER_REGISTRY')]) { - runAutoSemver("${DOCKER_REGISTRY}/auto-semver:${SELF_SEMVER_TAG}") - } + runAutoSemver("${env.DOCKER_REGISTRY}/auto-semver:${SELF_SEMVER_TAG}") } post{ // Update Git with status of version stage. @@ -34,10 +32,9 @@ pipeline { echo "Building ${env.SERVICE} docker image" - withCredentials([string(credentialsId: 'RbnDockerRegistry', variable: 'DOCKER_REGISTRY')]) { - // Docker build flags are set via the getDockerBuildFlags() shared library. - sh "docker build ${getDockerBuildFlags()} -t ${DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ." - } + // Docker build flags are set via the getDockerBuildFlags() shared library. + sh "docker build ${getDockerBuildFlags()} -t ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ." + sh "python setup.py sdist" } @@ -55,17 +52,15 @@ pipeline { { steps { withEcr { - withCredentials([string(credentialsId: 'RbnDockerRegistry', variable: 'DOCKER_REGISTRY')]) { - sh "docker push ${DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION}" + sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION}" script { if("${env.BRANCH_NAME}" == "develop") { - sh "docker tag ${DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ${DOCKER_REGISTRY}/${env.SERVICE}:latest" - sh "docker push ${DOCKER_REGISTRY}/${env.SERVICE}:latest" + sh "docker tag ${env.DOCKER_REGISTRY}/${env.SERVICE}:${env.VERSION} ${env.DOCKER_REGISTRY}/${env.SERVICE}:latest" + sh "docker push ${env.DOCKER_REGISTRY}/${env.SERVICE}:latest" } } - } } sh "aws s3 cp `ls -t ./dist/semver-* | head -1` s3://rbn-ops-pkg-us-east-1/${env.SERVICE}/${env.SERVICE}-${env.VERSION}.tar.gz" From 858f2fa6e149a1504250d45ab6f1ea84127f3b5f Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Thu, 19 Dec 2019 17:21:31 -0500 Subject: [PATCH 5/5] PIPELINE: Credentials --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3686b0a..cd68c2c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ pipeline { environment { SERVICE = 'auto-semver' GITHUB_URL = 'git@github.com:RightBrain-Networks/auto-semver.git' - env.DOCKER_REGISTRY = credentials('RbnDockerRegistry') + DOCKER_REGISTRY = credentials('RbnDockerRegistry') //Image tag to use for self-versioning SELF_SEMVER_TAG = "develop"