1- def workpath_linux_root = " /src/github.com/deis"
2-
3- def make = { String target ->
4- try {
5- sh " make ${ target} fileperms"
6- } catch (error) {
7- sh ' make fileperms'
8- throw error
9- }
10- }
11-
12- def gopath_linux = {
13- def gopath = pwd() + " /gopath"
14- env. GOPATH = gopath
15- gopath
16- }
17-
18- def workdir_linux = { String gopath , dest ->
19- gopath + workpath_linux_root + " /" + dest
20- }
21-
221def sh = { String cmd ->
232 wrap([$class : ' AnsiColorBuildWrapper' , ' colorMapName' : ' XTerm' ]) {
243 sh cmd
@@ -44,129 +23,130 @@ node('windows') {
4423 }
4524}
4625
47- node(' linux' ) {
48- def gopath = gopath_linux()
49- def workdir = workdir_linux(gopath, " controller-sdk-go" )
50-
51- dir(workdir) {
52- stage ' Checkout Linux'
53- checkout scm
54- stage ' Install Linux'
55- make ' bootstrap'
56- stage ' Test Linux'
57- make ' test-style'
58- make ' test-cover'
59- stage ' Upload to Codecov'
60- withCredentials([[$class : ' StringBinding' , credentialsId : ' 2da033eb-2e34-4efd-b090-ad892f348065' , variable : ' CODECOV_TOKEN' ]]) {
61- sh ' curl -s https://codecov.io/bash | bash'
62- }
63- }
64- }
65-
6626def git_commit = ' '
6727def git_branch = ' '
68- def go_repo = ' '
6928
7029stage ' Go & Git Info'
7130node(' linux' ) {
72-
73- def gopath = gopath_linux()
74- def workdir = workdir_linux(gopath, " controller-sdk-go" )
75-
76- dir(workdir) {
77- checkout scm
78-
79- // HACK: Recommended approach for getting command output is writing to and then reading a file.
80- sh ' mkdir -p tmp'
81- sh ' git describe --all > tmp/GIT_BRANCH'
82- sh ' git rev-parse HEAD > tmp/GIT_COMMIT'
83- sh ' go list . > tmp/GO_LIST'
84- git_branch = readFile(' tmp/GIT_BRANCH' ). trim()
85- git_commit = readFile(' tmp/GIT_COMMIT' ). trim()
86- go_repo = readFile(' tmp/GO_LIST' ). trim()
87-
88- if (git_branch != " remotes/origin/master" ) {
89- // Determine actual PR commit, if necessary
90- sh ' git rev-parse HEAD | git log --pretty=%P -n 1 --date-order > tmp/MERGE_COMMIT_PARENTS'
91- sh ' cat tmp/MERGE_COMMIT_PARENTS'
92- merge_commit_parents = readFile(' tmp/MERGE_COMMIT_PARENTS' ). trim()
93- if (merge_commit_parents. length() > 40 ) {
94- echo ' More than one merge commit parent signifies that the merge commit is not the PR commit'
95- echo " Changing git_commit from '${ git_commit} ' to '${ merge_commit_parents.take(40)} '"
96- git_commit = merge_commit_parents. take(40 )
97- } else {
98- echo ' Only one merge commit parent signifies that the merge commit is also the PR commit'
99- echo " Keeping git_commit as '${ git_commit} '"
100- }
101- // convert 'github.com/deis/controller-sdk-go' to 'github.com/${env.CHANGE_AUTHOR}/controller-sdk-go'
102- go_repo = go_repo. replace(' deis' , env. CHANGE_AUTHOR )
31+ checkout scm
32+ // HACK: Recommended approach for getting command output is writing to and then reading a file.
33+ sh ' mkdir -p tmp'
34+ sh ' git describe --all > tmp/GIT_BRANCH'
35+ sh ' git rev-parse HEAD > tmp/GIT_COMMIT'
36+ git_branch = readFile(' tmp/GIT_BRANCH' ). trim()
37+ git_commit = readFile(' tmp/GIT_COMMIT' ). trim()
38+
39+ if (git_branch != " remotes/origin/master" ) {
40+ // Determine actual PR commit, if necessary
41+ sh ' git rev-parse HEAD | git log --pretty=%P -n 1 --date-order > tmp/MERGE_COMMIT_PARENTS'
42+ sh ' cat tmp/MERGE_COMMIT_PARENTS'
43+ merge_commit_parents = readFile(' tmp/MERGE_COMMIT_PARENTS' ). trim()
44+ if (merge_commit_parents. length() > 40 ) {
45+ echo ' More than one merge commit parent signifies that the merge commit is not the PR commit'
46+ echo " Changing git_commit from '${ git_commit} ' to '${ merge_commit_parents.take(40)} '"
47+ git_commit = merge_commit_parents. take(40 )
48+ } else {
49+ echo ' Only one merge commit parent signifies that the merge commit is also the PR commit'
50+ echo " Keeping git_commit as '${ git_commit} '"
10351 }
10452 }
10553}
10654
107- stage ' Checkout workflow-cli repo and build/deploy with appropriate updates'
108- node(' linux' ) {
109- def repo = " workflow-cli"
110- def gopath = gopath_linux()
111- def workdir = workdir_linux(gopath, repo)
55+ def test_image = " quay.io/deisci/controller-sdk-go-dev:${ git_commit.take(7)} "
11256
113- def getBasePath = { String filepath ->
114- def filename = filepath. lastIndexOf(File . separator)
115- return filepath. substring(0 , filename)
116- }
117-
118- def gcs_cleanup_cmd = " sh -c 'rm -rf /.config/*'"
119- def gcs_bucket = " gs://workflow-cli"
120- def gcs_key = " tmp/key.json"
57+ node(' linux' ) {
58+ stage ' Build and push test container'
59+ checkout scm
60+ def quayUsername = " deisci+jenkins"
61+ def quayEmail = " deis+jenkins@deis.com"
62+ withCredentials([[$class : ' StringBinding' ,
63+ credentialsId : ' c67dc0a1-c8c4-4568-a73d-53ad8530ceeb' ,
64+ variable : ' QUAY_PASSWORD' ]]) {
65+
66+ sh """
67+ docker login -e="${ quayEmail} " -u="${ quayUsername} " -p="\$ {QUAY_PASSWORD}" quay.io
68+ docker build -t ${ test_image} .
69+ docker push ${ test_image}
70+ """
71+ }
72+ }
12173
122- def gcs_cmd = { String cmd ->
123- gcs_cmd = " docker run --rm -v ${ pwd()} /tmp:/.config -v ${ pwd()} /_dist:/upload google/cloud-sdk:latest "
124- try {
125- sh(gcs_cmd + cmd)
126- } catch (error) {
127- sh(gcs_cmd + gcs_cleanup_cmd)
128- throw error
74+ stage ' Lint and test container'
75+ parallel(
76+ lint : {
77+ node(' linux' ) {
78+ sh " docker run --rm ${ test_image} lint"
12979 }
130- }
131-
132- def upload_artifacts = {
133- withCredentials([[$class : ' FileBinding' , credentialsId : ' e80fd033-dd76-4d96-be79-6c272726fb82' , variable : ' GCSKEY' ]]) {
134- sh " mkdir -p ${ getBasePath(gcs_key)} "
135- sh " cat \"\$ {GCSKEY}\" > ${ gcs_key} "
136- gcs_cmd ' gcloud auth activate-service-account -q --key-file /.config/key.json'
137- gcs_cmd " gsutil -mq cp -a public-read -r /upload/* ${ gcs_bucket} "
138- gcs_cmd gcs_cleanup_cmd
80+ },
81+ test : {
82+ node(' linux' ) {
83+ withCredentials([[$class : ' StringBinding' ,
84+ credentialsId : ' 2da033eb-2e34-4efd-b090-ad892f348065' ,
85+ variable : ' CODECOV_TOKEN' ]]) {
86+ sh " docker run -e CODECOV_TOKEN=\$ {CODECOV_TOKEN} --rm ${ test_image} sh -c 'test-cover.sh && curl -s https://codecov.io/bash | bash'"
87+ }
13988 }
14089 }
90+ )
14191
142- dir(workdir) {
143- stage " Checkout ${ repo} "
144- git url : " https://github.com/deis/${ repo} .git" , branch : " master"
92+ stage ' Build and Upload CLI built with SDK'
93+
94+ def gcs_bucket = " gs://workflow-cli"
95+ def wcli_image = ' quay.io/deisci/workflow-cli-dev:latest'
14596
146- stage " Build ${ repo} "
147- if (git_branch != " remotes/origin/master" ) {
148- echo " Skipping build of 386 binaries to shorten CI for Pull Requests"
149- env. BUILD_ARCH = " amd64"
150- }
151- make ' bootstrap'
15297
153- stage " Update local glide.yaml with controller-sdk-go repo '${ go_repo} ' and version '${ git_commit} '"
98+ def upload_artifacts = { String dist_dir ->
99+ headers = " -h 'x-goog-meta-git-branch:${ git_branch} ' "
100+ headers + = " -h 'x-goog-meta-git-sha:${ git_commit} ' "
101+ headers + = " -h 'x-goog-meta-ci-job:${ env.JOB_NAME} ' "
102+ headers + = " -h 'x-goog-meta-ci-number:${ env.BUILD_NUMBER} ' "
103+ headers + = " -h 'x-goog-meta-ci-url:${ env.BUILD_URL} '"
154104
155- def pattern = " github\\ .com\\ /deis\\ /controller-sdk-go\\ n\\ s+version:\\ s+[a-f0-9]+"
156- def replacement = " ${ go_repo.replace("/", "\\/")} \\ n version: ${ git_commit} "
157- sh " perl -i -0pe 's/${ pattern} /${ replacement} /' glide.yaml"
105+ script = " sh -c 'echo \$ {GCS_KEY_JSON} | base64 -d - > /tmp/key.json "
106+ script + = " && gcloud auth activate-service-account -q --key-file /tmp/key.json "
107+ script + = " && gsutil -mq ${ headers} cp -a public-read -r /upload/* ${ gcs_bucket} "
108+ script + = " && rm -rf /upload/*'"
158109
159- def glideYaml = readFile(' glide.yaml' )
160- echo " Updated glide.yaml:\n ${ glideYaml} "
110+ withCredentials([[$class : ' StringBinding' ,
111+ credentialsId : ' 6561701c-b7b4-4796-83c4-9d87946799e4' ,
112+ variable : ' GCSKEY' ]]) {
113+ sh " docker run ${ dist_dir} -e GCS_KEY_JSON=\"\$ {GCSKEY}\" --rm ${ wcli_image} ${ script} "
114+ }
115+ }
161116
162- make ' glideup'
163- env. REVISION = git_commit. take(7 )
164- env. VERSION = " csdk-ci-" + git_commit. take(7 )
165- make ' build-revision'
117+ def mktmp = {
118+ // Create tmp directory to store files
119+ sh ' mktemp -d > tmp_dir'
120+ tmp = readFile(' tmp_dir' ). trim()
121+ echo " Storing binaries in ${ tmp} "
122+ sh ' rm tmp_dir'
123+ return tmp
124+ }
166125
167- stage " Deploy ${ repo} "
168- upload_artifacts()
126+ node(' linux' ) {
127+ flags = " "
128+ if (git_branch != " remotes/origin/master" ) {
129+ echo " Skipping build of 386 binaries to shorten CI for Pull Requests"
130+ flags + = " -e BUILD_ARCH=amd64"
169131 }
132+
133+ tmp_dir = mktmp()
134+ dist_dir = " -e DIST_DIR=/upload -v ${ tmp_dir} :/upload"
135+
136+ def pattern = " github\\ .com\\ /deis\\ /controller-sdk-go\\ n\\ s+version:\\ s+[a-f0-9]+"
137+ replacement = " github\\ .com\\ /deis\\ /controller-sdk-go\\ n"
138+ replacement + = " repo: https:\\ /\\ /github\\ .com\\ /${ env.CHANGE_AUTHOR} \\ /controller-sdk-go\\ .git\\ n"
139+ replacement + = " vcs: git\\ n"
140+ replacement + = " version: ${ git_commit} "
141+
142+ build_script = " sh -c 'perl -i -0pe \" s/${ pattern} /${ replacement} /\" glide.yaml "
143+ build_script + = " && rm -rf glide.lock vendor/github.com/deis/controller-sdk-go "
144+ build_script + = " && glide install "
145+ build_script + = " && make build-revision'"
146+ sh " docker run ${ flags} -e REVISION=${ git_commit.take(7)} ${ dist_dir} --rm ${ wcli_image} ${ build_script} "
147+
148+ upload_artifacts(dist_dir)
149+ sh " rm -rf ${ tmp_dir} "
170150}
171151
172152stage ' Trigger e2e tests'
@@ -193,7 +173,7 @@ waitUntil {
193173<div>Author: ${ env.CHANGE_AUTHOR} <br/>
194174Branch: ${ env.BRANCH_NAME} <br/>
195175Commit: ${ env.CHANGE_TITLE} <br/>
196- <p><a href="${ env.BUILD_URL} console/ ">Click here</a> to view build logs.</p>
176+ <p><a href="${ env.BUILD_URL} console">Click here</a> to view build logs.</p>
197177<p><a href="${ env.BUILD_URL} input/">Click here</a> to restart e2e.</p>
198178</div>
199179</html>
0 commit comments