From 3b9143da4bb681ad745545f98fbaac02b6ebe953 Mon Sep 17 00:00:00 2001 From: Zhao Xiaojie Date: Wed, 29 May 2019 23:20:54 +0800 Subject: [PATCH] Fix the pipeline script --- Jenkinsfile | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ac8e2f9..f2c6b0c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,24 +3,42 @@ pipeline { label "golang" } + environment { + IMAGE_TAG = "" + } + stages{ stage("build") { steps { - sh 'make build' + container('golang'){ + sh ''' + CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -a -installsuffix cgo -o bin/wechat-backend + upx bin/wechat-backend + ''' + } } } stage("image") { steps { - sh 'make image' + container('golang'){ + sh ''' + IMAGE_TAG=$(git rev-parse --short HEAD) + docker build -t surenpi/jenkins-wechat:$IMAGE_TAG . + docker push surenpi/jenkins-wechat:$IMAGE_TAG + ''' + } } } stage("push-image") { + environment { + DOCKER_CREDS = credentials('docker-surenpi') + } steps { - withCredentials([usernamePassword(credentialsId: '', passwordVariable: 'passwd', usernameVariable: 'user')]) { + container('golang') { sh ''' - docker login -u $user -p $passwd + docker login -u $DOCKER_CREDS_USR -p $DOCKER_CREDS_PSW make push-image docker logout ''' -- GitLab