Reputation: 83
I configured my jenkins job (freestyle) with dev/test/prod environments using choice parameter with "This project is parameterised" option form jenkins job configuration.
I have setup webhook in my github soouce as https://myjenkins/github-webhook/ . when i commit a change to github repo, it is triggering build in jenkins always with "dev" environment option. 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?
Upvotes: 2
Views: 4830
Reputation: 651
I don't know if I am late but this is for those who are seeking its answer by date.The answer is Just assign same name of your variable of build parameter in the post content parameter or any other section like headers or request. Like if I have set the branch name in DEPLOY_TO variable and it create build according to this name. But now we want to take branch name from webhook instead of manually selection. All we need to do is to set variable with same name like we will set DEPLOY_TO of value $.push.changes[0].new.name. It will work like a champ. here in post parameters and look at this
Upvotes: 0
Reputation: 16505
Use some branch strategy and in your job do something like:
IF BRANCH endsWith RELEASE
deploy to testing
IF BRANCH endsWith SNAPSHOT
deploy to dev
IF BRANCH == MASTER
deploy to production
ETC ...
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. Most important are:
Then in your continuous integration server you must parse this Json to get important values. In jenkis there are several plugins like: Generic webhook, easy webhook plugin, github plugin, etc
After of values extraction you can apply simple or complex validations using branch name, commit message, commit author, etc. For instance:
Your imagination is your only limitation.
Useful links:
Upvotes: 4