Setting custom build in Jenkins - jenkins

I'm trying to create custom build format in Jenkins. My build ideally would have the ${GIT_TAG}.${BUILD_NUMBER}
I've installed the buildnamesetter plugin, https://wiki.jenkins-ci.org/display/JENKINS/Build+Name+Setter+Plugin.
However I can't figure out how can I access the build parameters, there is a way to access the environment parameters but not the build ones.
Eventually all I get with ${GIT_TAG}.${BUILD_NUMBER} is the running number of the build such as: #24 and error in the execution log:
Unrecognized macro 'GIT_TAG' in '${GIT_TAG}.${BUILD_NUMBER}'
I might be looking in the wrong direction and different plugin can be used, any help will be appreciated.
I'm still stuck since I have a requirement to have additional parameter as in the build number string and this one is selected by the user from Choice Parameter and Choice Parameter can't be converted to be environment AFAIK. Any ideas would be very appreciated.

Ok, finally after struggling for few hours seems that solution was found I'll post it here in case it might help to someone else:
Need the following plugins:
build-name-setter
Create your run time parameter that set by the user
Use the following built in Jenkins functionality to prepare the environment before the run:
Set the Properties Content to have any parameter that your user/script supplies and you would like it to be ENV parameter
How I used it:
When referring the env parameter in the build-name-setter plugin use the following example as reference on how to access the environment parameters ${ENV,var="SELECTED_DEVICE"}
How I used it:

Related

Jenkins: Pass environment variable to the job parameter

Since I have the same static rarely changed parameters used by several jobs I decided to put it somewhere in one place of my Jenkins and use it across jobs.
The first thought that came to my mind was to move my 'static data' to the environment variables and get it using Active choice reactive parameter plugin which allows running simple groovy scripts on the job parameters page.
Please note that I know how to get environment parameters in the pipeline, but I do really need to have this data on the build with parameters screen, e.g. once I clicked build with parameters - I need my groovy code inside Active choice reactive parameter was able to read this environment variable and display as a parameter to the user.
A simple example of this need:
The environment variable contains the list of servers, the job is going to perform deployment of the application to the selected server. In this case, I want to be able to write something like this in the groovy script section of Active choice reactive parameter:
return[${env.SERVERS_LIST}]
Unfortunately the example above doesn't work. I wasn't able to find any working solution for this yet.
Well, after a few more tries I finally found a solution.
Instead of trying to read the environment variable in the pipeline manner the simple
return [SERVERS_LIST]
works perfect

Set a file path from Jenkins' choice parameter

I struggled few days, But still, I could not find a solution for this.
I am trying to deploy Marathon apps with Jenkins and follow this tutorial.
https://docs.mesosphere.com/1.10/tutorials/deploy-on-marathon/
I want to configure a parameterized project for this. Eg :
Builder can select one choice out of four choices.
As an Example: Suppose the user has selected the vault option.
Then I need to change the file name(Definition File) base on what user has selected on above options.
I am using Marathon deployment plugin.
For this configs I am getting below error :
18:12:40 [Marathon] Application Definition not found:
18:12:40 [Marathon] Could not find file 'deployment_files/"($CONTAINER)".json'
18:12:40 Build step 'Marathon Deployment' changed build result to FAILURE
Could you please help me to achieve this problem or suggest a better way to do this?
When referencing a build parameter in another setting (or another parameter) the way you are trying to, I typically use the following format:
deployment_files/${CONTAINER}.json
There is some good reading to be done in the following thread on using $VAR vs ${VAR}

I Want to pass Jenkins parameters into a build DSL Script. It is not taking this parameter.

I have defined a build flow with the following script in Jenkins in a Build Flow
Build("Server Repository","ENV")
where ENV is a choice parameter defined in the Build Flow Item.When I am building it is not at all using my chosen parameter. It is taking default and same values at every build.
Build("Server Repository",$ENV)
Has been also tried. It does not work.Plus declaring Jenkins Parameters too have been tried.
ENV=${ENV}
Build("Server Repository",ENV)
Has been tried too. Suggest some possible ways to work this out.

How to configure parameters with time stamp

I have a job ( parameterized build) I am using BUILD_ID as a parameter and I need to add time stamp for the every BUILD_ID.
How to add time-stamp to the parameter.
I need the BUILD_ID value like Test_Build_{time-stamp}.
Kindly help me
There are numerous ways to do this.
Probably your best bet is the Dynamic Parameter Plugin. On the plugin page, one of its main examples does almost exactly what you described.
The Active Choices Plugin allows you to run groovy code to generate your parameter value(s). Here's a screenshot of the plugin setup along with the groovy code:
The EnvInject Plugin allows you to insert environment variables from a properties file as a build step. Using this method you would basically have to have 2 build steps, one to create the properties file and another to read it.
Or using the Groovy Plugin, you can add a groovy script build step to modify the parameter value.
I'm sure there a number of other ways to accomplish this as well.
Install Zen Timestamp plugin and use variable $BUILD_TIMESTAMP

Jenkins global variables

I'm trying to use global variables within Jenkins on Windows to "automagically" retrieve the proper code base from our SCM system, but in each case that I've tried the variable substitution is not happening.
I've set up some global variables, with default values, within "Configure System" and have tried to access them with $VARIABLE, ${VARIABLE} and %VARIABLE% as part of the Branch field for the Surround SCM plugin with no success whatsoever.
I've also installed the Global Variable String Parameter plugin with the same success rate (0%). Using a literal value works just fine, but no type of variable substitution seems to work at all and I'm sure that someone has come upon this before and resolved it.
I've tried searching for something similar to this but nothing really approaches this usage of globals, instead it is normally discussed as a function within an external script, or parameter passed to a batch file, etc.
I've run "set" as the first step and can see that the variable is available, but the substitution is just not happening. If it means I will have to script something, then so be it, as I am trying to make this extremely flexible and as headache free as possible, but that isn't seeming to be the case in this case thus far.
My problem is eerily similar to this post: How are environment variables used in Jenkins with Windows Batch Command?, but again, I'm not looking to script this as it is a MUCH simpler solution to use the variable values directly.
from https://wiki.jenkins-ci.org/display/JENKINS/Surround+SCM+Plugin
Troubleshooting
Please contact Seapine support with questions about the integration or
to report bugs or feature requests.
Set your Jenkins project to be parameterized. Create a string parameter GIT_BRANCH that will be your branch variable (for example).
Under Source Control Management, use your branch variable in the form $GIT_BRANCH
That’s it. When you run your project, you will be prompted to enter a value for your GIT_BRANCH parameter.

Resources