简体   繁体   English

使用github webhooks参数化的jenkins构建

[英]parameterized jenkins build with github webhooks

I configured my jenkins job (freestyle) with dev/test/prod environments using choice parameter with "This project is parameterised" option form jenkins job configuration. 我在jenkins作业配置中使用带有“此项目已参数化”选项的选择参数,在dev / test / prod环境中配置了我的jenkins作业(自由式)。

I have setup webhook in my github soouce as https://myjenkins/github-webhook/ . 我在github源中将webhook设置为https:// myjenkins / github-webhook / when i commit a change to github repo, it is triggering build in jenkins always with "dev" environment option. 当我对github repo进行更改时,它总是使用“ dev”环境选项触发jenkins中的构建。 how to make it to choose any of the other environment, based on my requirement? 如何根据我的要求选择其他任何环境?

I googled but didn't find correct answer. 我用谷歌搜索,但没有找到正确的答案。 can someone help me? 有人能帮我吗?

Short answer 简短答案

Use some branch strategy and in your job do something like: 使用一些分支策略,然后在您的工作中执行以下操作:

IF BRANCH == DEVELOPMENT
  deploy to dev
IF BRANCH endsWith SNAPSHOT
  deploy to dev
IF BRANCH == MASTER
  deploy to production
ETC ...

Detailed answer 详细答案

When a developer perform a git push to Github, Bitbucket or Gitlab, these platforms send a Json to your continuous integration server(jenkis, travis,etc) with a lot of information related to the push event. 当开发人员对Github,Bitbucket或Gitlab执行git push时,这些平台会将Json发送给Json到您的持续集成服务器(jenkis,travis等),其中包含与push事件相关的大量信息。 Most important are: 最重要的是:

  • repository name 仓库名称
  • target branch name: Branch who receive the git push 目标分支名称:接收git push的分支
  • commit message 提交信息
  • commit author 提交作者

网络挂接

Then in your continuous integration server you must parse this Json to get important values. 然后,在您的持续集成服务器中,您必须解析此Json以获得重要的值。 In jenkis there are several plugins like: Generic webhook, easy webhook plugin , github plugin, etc 在jenkis中,有几个插件,例如:通用webhook, easy webhook插件 ,github插件等。

After of values extraction you can apply simple or complex validations using branch name, commit message, commit author, etc. For instance: 提取值之后,您可以使用分支名称,提交消息,提交作者等来应用简单或复杂的验证。例如:

  • only master branch could be deployed to production environment 只能将主分支部署到生产环境
  • only branch whose name ends with "snapshot" could be deployed to development environment: fix-issue-snapshot, feature-abc-snapshot, etc 只能将名称以“快照”结尾的分支部署到开发环境:fix-issue-snapshot,feature-abc-snapshot等
  • if commit message contains "WIP" it will mean that it is still in progress or development, then no deployment will be made. 如果提交消息包含“ WIP”,则表示它仍在进行或开发中,则不会进行部署。
  • only push of team lead will be deployed 仅推动团队领导
  • if build , unit test and other validations are passed in the source code of feature-100- development branch, a new branch called feature-100- release will be created, then this branch will be deployed to testing environment. 如果在feature-100- development分支的源代码中传递了build,unit test和其他验证,则将创建一个称为feature-100- release的新分支,然后将该分支部署到测试环境。 This *release branch is candidate to be deployed in production if Q&A Team does not detect any functional issue. 如果Q&A团队未检测到任何功能问题,则此* release分支适合在生产中部署。
  • any other automation flow from simple to complex. 从简单到复杂的任何其他自动化流程。

Your imagination is your only limitation. 您的想象力是您唯一的限制。

Useful links: 有用的链接:

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

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