Example
Create a build job (according to your requirement). For this example I have created a freestyle job (AutoPush) to perform ANT build.
We are going to create two variables, PUSH (Choice Parameter) and TAG_NUMBER (String Parameter).
We can choose the value YES or NO for PUSH, this will decide whether to push the code to a tag or not on successful build.
We can specify a tag name (ex. 1.0.1) for TAG_NUMBER to create a new tag (ex. 1.0.1) in the remote repository with the same name or specify an existing tag name to update an existing tag.
![enter image description here](https://i.stack.imgur.com/U1hcD.png)
Now let’s move on to the job configuration.
- Check the “This project is parameterized” checkbox and create a Choice Parameter called “PUSH” and provide YES and NO as the choices. This parameter will decide whether you want to push the code to a specific Tag/Release or not.
![enter image description here](https://i.stack.imgur.com/cOUgN.png)
- Then create a String Parameter called “TAG_NUMBER”, using this parameter we can specify a new tag number to create a new tag or specify an existing tag number to update an existing tag.
![enter image description here](https://i.stack.imgur.com/tQh44.png)
- In Source Code Management section choose Git and provide the repository URL. This repository contains the source code that you are going to build and after a successful build a release tag will be created on the same repository.
![enter image description here](https://i.stack.imgur.com/PgJJu.png)
- After adding the repository details click on advanced and provide a name to your repository which will later get referred in the Git Publisher plugin to identify the repository.
![enter image description here](https://i.stack.imgur.com/lyKCw.png)
![enter image description here](https://i.stack.imgur.com/9ur7Z.png)
- Then add the build step. In this example I am building an ANT project.
![enter image description here](https://i.stack.imgur.com/9l98b.png)
- Now in “Post-build Actions” section select “Flexi Publish” plugin. Select the value “And” from the dropdown for Conditional action (Run?). Then select “String Match” from the dropdown for the Run condition (&&).
![enter image description here](https://i.stack.imgur.com/C2FYN.png)
![enter image description here](https://i.stack.imgur.com/tccWc.png)
![enter image description here](https://i.stack.imgur.com/NK1Y4.png)
- After selecting the string match specify $PUSH as String 1 value and YES as String 2 value. So when you will run the build if you choose the value of PUSH as YES, it will compare the String 1 (=$PUSH) and String 2 (=YES) and trigger the Git push operation and if you choose NO it won’t trigger the Git push operation.
Choose the value of PUSH -> YES OR NO -> Chosen value “YES”
then, $PUSH = YES
AS String 1 = $PUSH => String 1 = YES
Again, String 2 = YES, hence String 2 == String 1 (String match)
Then, trigger the Git push action.
![enter image description here](https://i.stack.imgur.com/ILfu6.png)
- Now click on Add dropdown option to add the Git publisher action that will be triggered on the basis of the string match condition.
![enter image description here](https://i.stack.imgur.com/gdKSW.png)
![enter image description here](https://i.stack.imgur.com/G83MK.png)
- After selecting Git Publisher, do the configuration as follows:
![enter image description here](https://i.stack.imgur.com/uOhDL.png)
After the configuration save the job and you are done.