Upload build artifact to Github as release in Jenkins

StephenKing picture StephenKing · Jul 5, 2014 · Viewed 14.7k times · Source

I'm searching for a way to upload a build artifact as Github Release in Jenkins as post-build action or publisher - similar to Publish Over.

This is not yet supported by the Github plugin for Jenkins (JENKINS-18598).

I've been looking into the postbuild-task plugin, but this doesn't seem to support environment variables (which I assume would be helpful to prevent logging my API token in the build output).

Has anybody done this, yet? What would be a good way to solve this with Jenkins? Uploading via cURL or via a CLI client (e.g. the Go-based github-release).

Answer

Asaf Shveki picture Asaf Shveki · Jan 20, 2015

I solved it by using the github-release tool. Works like a charm and very easy.

  1. Add a relevant parameters to the build
  2. Add a shell script to your post build steps
  3. Enter this code:
echo "Compressing artifacts into one file"
zip -r artifacts.zip artifacts_folder

echo "Exporting token and enterprise api to enable github-release tool"
export GITHUB_TOKEN=$$$$$$$$$$$$
export GITHUB_API=https://git.{your domain}.com/api/v3 # needed only for enterprise

echo "Deleting release from github before creating new one"
github-release delete --user ${GITHUB_ORGANIZATION} --repo ${GITHUB_REPO} --tag ${VERSION_NAME}

echo "Creating a new release in github"
github-release release --user ${GITHUB_ORGANIZATION} --repo ${GITHUB_REPO} --tag ${VERSION_NAME} --name "${VERSION_NAME}"

echo "Uploading the artifacts into github"
github-release upload --user ${GITHUB_ORGANIZATION} --repo ${GITHUB_REPO} --tag ${VERSION_NAME} --name "${PROJECT_NAME}-${VERSION_NAME}.zip" --file artifacts.zip