Retrieving Jenkins job name using groovy script in Active Choice Reactive Parameter - jenkins

I am unable to retrieve the Job name using groovy script below. Even when I run this script in the Execute System Groovy Build Step, it gives me the error as.
Error:
groovy.lang.MissingPropertyException: No such property: jenkinsProject for class: groovy.lang.Binding
----
def jobName = this.binding.jenkinsProject.name
----
I found in the below link that it has worked for someone, but somehow not working for me. Can anyone help please?
How to get the job name on a groovy dynamic parameter in Jenkins

The v1.3 and v1.4 (released in a couple of days once manual testing is done) both should support this feature. Just use jenkinsProject in you code and that should work fine. Other wise just let us know via issues.jenkins-ci.org, component=active-choices-plugin.
The v1.4 has a bug fix that allows you to use this variable with Matrix projects as well.
Hope that helps,
Bruno

Related

troubleshoot active choice reactive reference parameter in jenkins

I am facing issues with active choice and reactive choice parameter groovy script in jenkins.
Existing groovy script which was working previously, now has the issue as a result I cannot pass the input correctly within the job.
Is there a possible way to troubleshoot this groovy as we don't have any IDE and jenkins compile those scripts internally.
Do you know about the script console at https://your-jenkins-server/script ?

Getting Jenkins to fail when Swagger-Diff returns differences

So I have a Jenkins job I'm testing right now that is comparing two Swagger contract files like this.
I'm using this to run my compare:
npx swagger-diff <url1> <url2>
What happens when I modify the contract on two of the endpoints I only get a warning and not an error and it wont cause Jenkins to report that the build failed. Is there anyway I can configure this to ensure that the Jenkins build will fail if there are contract differences?
The ultimate goal if this is to be able to watch an endpoint so that we know when it is failing.
So I ended up solving this by using the Jenkins plugin Log Parser to read through the log and look for specific breaking changes that we determined would be "fatal".

how to get jenkins build urls related to a jira fix version?

I need some help to ingrate Jenkins with jira my user case is this one : i would like to feed urls of builds related to a Jira fix version. This is important for us ( audit & compliance purposes )
How can i do that ?
Think you in advance.
regards,
This is how we handled it:
Add a custom text field to every jira issue type. it can be 'build number' or 'build url' or whatever information you need to display regarding the jenkins build
Create a python script that receives as parameters a list of jira issues and a build number.
Using the JIRA python module (pip install jira), the script creates a connection to jira, goes over the list of issues and updates the custom field above to the given build number.
if the list of issues is not known in advance, then instead of parameter you can provide (or hard-code) a JQL query which the script can use to obtain the list of issues.
Depending on your needs, you may want to skip updating issues who already has a build
number set (either manually or by a previous build)
(Sorry, i can't share exact code but it shouldn't be complicated.)
In your Jenkins build, add a 'batch command' item which runs that python script with the appropriate parameters.

How to export windows batch variables as build parameters to following steps in Jenkins?

In Jenkins, is it possible to export windows batch variables as build parameters? I know using build parameters inside windows batch blocks is, I use it a lot.
For example, I have a windows batch block that creates a variable, say A, like
SET A="MyVar"
Is it possible to use it in running MSBuild, passing it like it was a build parameter, in the (working) syntax of /p:AssemblyName=%A% or /p:AssemblyName=${A} ?
Neither of these seem to work (my variable is always empty).
Update: #Tuffwer suggested using the EnvInject plugin. I have been trying, but so far without success. Here's a sample I created to illustrate my original intent:
I want to create a variable which contents will be determined based on a condition applied in one of the build parameters. Then, I want to use that variable as a parameter to the MsBuild command line, using the /p:[Key]=[Value] syntax (which requires the Jenkins MsBuild plugin, if I am not wrong).
I still can't get this to work, now using EnvInject. I need to reference the value of a windows batch variable inside a further build step.
Update II: I turned into Environment Script Plugin, which did the job for me.
Tuffwer suggested using the EnvInject plugin, I tried did not succeed attaining what I intended. I edited my post including my EnvInject attempt, but in the meantime went searching again for other solutions.
This time I came across the Environment Script Plugin, which did the job for me.
Steps:
Mark Generate environment variables from script
For each variable you want to "export", you need to issue an echo [varName]=[value] statement.
That's all.
My build then creates an assembly named either TRUE.exe or FALSE.exe, depending on the build parameter MyBool value.

Use build parameter in downstream build configuration in Jenkins

I am using the Parameterized Trigger Plugin on my Jenkins server and I am trying to use a pre-defined parameter used while triggering my downstream build. Unfortunately, I can't get it to work the way I want so I wanted to see if someone could point out what I am doing wrong. Here is my parameterized trigger:
And here is where I try to consume the build parameter in a downstream build:
However, this does not seem to work an the project name shows up as blank when the build gets triggered. Is this doable? Am I doing this right? Any help would be appreciated. Thanks!
There are documented issues of this type of behavior in Jenkins version 2.3
However, the following worked for me:
You need to extend your triggered/downstream jobs (every "Job B") to accept additional parameters. Enable in project B the option "This project is parameterized" and add parameters with the same name as the one passed by the project A.

Resources