Automatically release a tagged version to github
@@ -30,6 +30,7 @@ pipeline {
stash name: 'e2e'
}
if(!(env.BRANCH_NAME ==~ "PR-\\d+")) {
+ stash name: 'artifacts', includes: '*.tar.gz', excludes: '*-e2e-*'
archiveArtifacts '*.tar.gz'
}
} finally {
@@ -80,5 +81,32 @@ pipeline {
}
}
}
+ stage('Release') {
+ agent {
+ label "linux"
+ }
+ when {
+ buildingTag()
+ }
+ steps {
+ dir('src/github.com/docker/lunchbox') {
+ deleteDir()
+ sh 'rm -f *.tar.gz'
+ unstash 'artifacts'
+ release('docker/lunchbox')
+ }
+ }
+ }
+ }
+}
+
+def release(repo) {
+ withCredentials([[$class: 'StringBinding', credentialsId: 'github-release-token', variable: 'GITHUB_TOKEN']]) {
+ def data = "{\"tag_name\": \"$BRANCH_NAME\", \"name\": \"$BRANCH_NAME\", \"draft\": true, \"prerelease\": true}"
+ def url = "https://api.github.com/repos/$repo/releases"
+ def reply = sh(returnStdout: true, script: "curl -sSf -H \"Authorization: token $GITHUB_TOKEN\" -H \"Accept: application/json\" -H \"Content-type: application/json\" -X POST -d '$data' $url")
+ def release = readJSON text: reply
+ url = release.upload_url.replace('{?name,label}', '')
+ sh("ls *.tar.gz | xargs -i curl -sf -H \"Authorization: token $GITHUB_TOKEN\" -H \"Accept: application/json\" -H \"Content-type: application/gzip\" -X POST --data-binary \"@{}\" $url?name={}")
}
}
