简体   繁体   English

将构建工件上载到Github,作为Jenkins的发布

[英]Upload build artifact to Github as release in Jenkins

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 . 我正在寻找一种方法来将构建工件上传为Jenkins中的Github Release作为构建后操作或发布者 - 类似于Publish Over

This is not yet supported by the Github plugin for Jenkins ( JENKINS-18598 ). Jenkins的Github插件( 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). 我一直在研究postbuild-task插件,但这似乎不支持环境变量(我认为这有助于防止在构建输出中记录我的API令牌)。

Has anybody done this, yet? 有没有人这样做过呢? What would be a good way to solve this with Jenkins? 用Jenkins解决这个问题的好方法是什么? Uploading via cURL or via a CLI client (eg the Go-based github-release ). 通过cURL或CLI客户端上传(例如基于Go的github-release )。

I solved it by using the github-release tool. 我通过使用github-release工具解决了它。 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 在后期构建步骤中添加shell脚本
  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

I think you are on track! 我认为你正在走上正轨!

  1. Add the post build task plugin to Jenkins 将post build任务插件添加到Jenkins
  2. Use the 'Run script only if all previous steps were successful' option 使用“仅当前面的所有步骤都成功时运行脚本”选项
  3. I would create Jenkins parameters for the release name, tag name etc. and would save those along with your credentials to a file as a last step in the build process (before the post build task execution). 我将为版本名称,标记名称等创建Jenkins参数,并将这些参数与您的凭据一起保存到文件中,作为构建过程的最后一步(在构建后任务执行之前)。
  4. Add a short script to the post build task step that calls the Github API: 在调用Github API的post build任务步骤中添加一个简短的脚本:
  5. Set the environment variables from your saved file and delete it 从保存的文件中设置环境变量并将其删除
  6. CURL POST for https://developer.github.com/v3/repos/releases/#create-a-release (You could use the Jenkings Groovy post build plugin instead of the post build task plugin and access the environment variables without saving them into a file but it would add so much complexity that it is not worth to use that plugin.) 用于https://developer.github.com/v3/repos/releases/#create-a-release的 CURL POST(您可以使用Jenkings Groovy post构建插件而不是post build任务插件并访问环境变量而不保存它们进入一个文件,但它会增加太多的复杂性,以至于不值得使用该插件。)
  7. CURL POST to upload the artifact: https://developer.github.com/v3/repos/releases/#upload-a-release-asset CURL POST上传工件: https//developer.github.com/v3/repos/releases/#upload-a-release-asset

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM