1
votes

I have written a workflow script which builds our project. Inside the node-block I checkout our sources from git:

node('nodeA') {
  git url: 'https://github.com/foo/bar.git'
  ...
}

The workflow script itself is part of the source code. Now different developers have different forks of the git repo. Therefore the URL is different and I would like to get rid of the hard-coded URL in the script.

Is it possible to specify the Git repo URL in the Jenkins job configuration? And how gets the actual node the source code?

3

3 Answers

2
votes

The easiest way is to use the Workflow: Multibranch plugin (currently 1.9-beta-1, on the experimental update center), in which case the Git configuration is on the job and your script merely runs

checkout scm

There is not currently a branch source handling multiple forks (or pull requests), but this is a possible integration.

2
votes

Another more manual possibility is to make the job parameterized, and use the same parameter name in both places. So if you defined a string parameter GIT_URL, specify $GIT_URL in the remote repository location in the job’s visual configuration (assuming you are using Groovy CPS DSL from SCM), and in the script use

git GIT_URL

Then each person triggering the job must define the location of their fork. (Or you could have the parameter include just the fork name, etc.)

0
votes

Use git SCM to achieve this.

For using git scm in jenkins you should install 2 plugins.

Git and Git client

Install git client plugin before installing git plugin.