Skip to content

Instantly share code, notes, and snippets.

@ntakouris
Created August 24, 2017 09:32
Show Gist options
  • Save ntakouris/a296d626c20cbf3879db684b4a393cc6 to your computer and use it in GitHub Desktop.
Save ntakouris/a296d626c20cbf3879db684b4a393cc6 to your computer and use it in GitHub Desktop.
stage('BitBucket Publish'){
//Find out commit hash
sh 'git rev-parse HEAD > commit'
def commit = readFile('commit').trim()
//Find out current branch
sh 'git name-rev --name-only HEAD > GIT_BRANCH'
def branch = readFile('GIT_BRANCH').trim()
//strip off repo-name/origin/ (optional)
branch = branch.substring(branch.lastIndexOf('/') + 1)
def archive = "${GOPATH}/project-${branch}-${commit}.tar.gz"
echo "Building Archive ${archive}"
sh """tar -cvzf ${archive} $GOPATH/src/cmd/project/project"""
echo "Uploading ${archive} to BitBucket Downloads"
withCredentials([string(credentialsId: 'bb-upload-key', variable: 'KEY')]) {
sh """curl -s -u 'user:${KEY}' -X POST 'Downloads Page URL' --form files=@'${archive}' --fail"""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment