is there a way to call via code the GUI field "Repository URL" in order to use its value on my Jenkins pipeline?
The url of your git repository is part of the scm object. You can get the url by calling scm.getUserRemoteConfigs()[0].getUrl().
The method getUserRemoteConfigs() will return a list with instances of type UserRemoteConfig. This class has a method called getUrl() which will return the configured url as a string.
Further information: https://javadoc.jenkins.io/plugin/git/hudson/plugins/git/GitSCM.html
You can use GIT_URL environment variable of jenkins.
i.e. echo "Git URL is ${GIT_URL}"
This will give you the git url used in the current jenkins job.
Related
I'd like to understand this behavior more.
I don't want to have to shell out to git to get basic Git info like the repo name, branch name, and user name.
env.BRANCH_NAME is always populated so that's easy.
I can retrieve the repo name like this: scm.getUserRemoteConfigs()[0].getUrl().tokenize('/').last().split("\\.")[0]. Pretty gnarly but it works.
I see the gitConfigEmail property of the scm object is always null though.
Will the scm object ever be populated with the git user name?
I'm using the Bitbucket plugin.
I am trying to use Generic Webhook Trigger plugin in Jenkins to trigger build in case any PR is raised on my GitHub repo. For starters I defined a variable "current_status" mapping it to "action" field within the json payload to be received from GitHub. While the build is getting triggered on raising a PR but the value for current_status is coming as null. The content-type for my GitHub webhook is "application/json"
The GitHub payload generated against the PR event has action field in it :
"action": "opened",
But when I try to print this variable using println "${params.current_status}" in my pipeline, the value is printed as null.
Also when I try to execute a step based on the value of the variable using
when {
expression { return params.current_status == "opened" }
}
the stage is skipped even though the value as per the action in the GitHub payload is "opened"
For debugging the issue when I selected the option to print the contributed variables in the job log I could see value of the current_status value as opened
But when I refer this variable in my pipeline its value comes out to be null somehow.
As a workaround made my pipeline parmeterized, using the same name for the variable as the one defined in the Generic Webhook Trigger Plugin section (current_status) and then referred to it within my Jenkinsfile and it worked.(the value for the variable reflected the value received in the json payload from GitHub).
Finally I found the solution. For anyone who might be facing the same issue you can refer to the variable defined within the Generic Webhook Trigger plugin directly as a Groovy variable. In my case I tried to the use the variable current_status directly without referrring it via params and it worked as expected.
The other approach of defining the variable via parmeterized pipeline might be helpful wherein we would want to run the build manually.
1.How to replace back slash with forward slash in Jenkins on UI :- SVN_EAR_PATH (String parameter)
You cannot change a parameter's value in a freestyle job. When you use git you can use the Git parameter plugin to present the user with all the available tags, but I'm not aware of any Subversion alternative unfortunately.
I think your best effort in this case would be to write a pipeline job and then you will have control over the parameter's value (you could write SVN_EAR_PATH.replace('\\', '/'))
I want to remotely build a jenkins job using multiple parameter through restassured API jobs in java.
I tried using the following link
http://localhost:8080/job/jobname/buildWithParameters?token=TOKEN&FEATURE="parameter1_value";FEATURE2=parameter2_value
but this url results in triggering a job with passing both the parameter values within a single parameter.
get("http://localhost:8080/job/jobname/buildWithParameters?token=TOKEN&FEATURE="parameter1_value";FEATURE2=parameter2_value");
This is the response json of jenkins job
The parameter defined in configuration of a Jenkins job should be a "String Parameter" in order to set them using URL.
And the modified URL should be like -
http://localhost:8080/job/jobname/buildWithParameters?parameter=parameter1_value¶meter2=parameter2_value
I am setting up a parameterized build on my Jenkins server.
Basically I want to have the git branch name as a parameter. Then I want to use that parameter in various other fields in the job config.
I don't know if this is even possible, but I hope that it might be as it seems an obvious need.
The only docs I could find is this old wiki page
https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build
It shows that build parameter is available as an ENV var, but it doesn't show how to use it elsewhere in the job config.
despite being undocumented, this syntax works in job config fields
${PARAM_NAME}
Just use $PARAM_NAME anywhere in the configure.
The easiest way is to use the "Git parameter" parameter type in your config and then you can reference that simply in the Source Code Management section - see here. This assumes that the Jenkins instance has the Git parameter plugin installed.
If you don't have that option, then:
you can simply add a String parameter to the configuration and use that in you configuration, but you need to uncheck "Lightweight checkout" to avoid errors like this:
stderr: fatal: Couldn't find remote ref refs/heads/${BRANCH}
String parameter declaration:
String parameter usage:
Source of pictures