1

I have a Jenkins pipeline job which is configured as "pipeline script from SCM", pointing to a Jenkinsfile in SVN. For example, the SVN URL is http://example.com/svn/myproject/trunk/ The jenkins master does a shallow checkout (root files only) and then finds the Jenkinsfile at the root.

This URL is repeated within the Jenkinsfile, in the step which checks out the SVN workspace on a separate jenkins agent.

So whenever I clone the jenkins job for a new branch, I need to fix up the URL in two different places: once in the jenkins job config where it points at the Jenkinsfile, and once within the Jenkinsfile. Is there a way to avoid this, e.g. by reading the current job configuration from the Jenkinsfile?

3
  • Not sure about reading config of the same job, however, this can be done by parameterzing the URL. Once it is passed as parameter, same can be fed to SCM and can be used in Jenkinsfile. Commented May 26, 2020 at 17:17
  • @saurabh14292 I found a way without parameterization, see answer below Commented May 26, 2020 at 19:35
  • @saurabh14292 Hello, I tried a lot of methods, why can’t I parameterize the svn url in the pipeline script from SCM, such as ${SVN_URL}, $SVN_URL, etc. are invalid, can you help me? Commented Jun 9, 2021 at 5:51

1 Answer 1

2

In the end, I managed to retrieve the SVN URL from the job configuration via the scm global, store it in a SVNURL environment variable, and then use it in the checkout step instead of hardcoding the SVN URL.

stage('stage-name') { steps { // Get the SVN URL from the pipeline job configuration script { env.SVNURL = scm.getLocations()[0].getURL() } checkout([ $class: 'SubversionSCM', filterChangelog: false, ignoreDirPropChanges: false, locations: [[ credentialsId: '<guid>', depthOption: 'infinity', ignoreExternalsOption: false, local: 'my-checkout-folder', remote: env.SVNURL ]], workspaceUpdater: [$class: 'UpdateWithCleanUpdater'] ]) } } 
Sign up to request clarification or add additional context in comments.

1 Comment

Hello, every time you add a new branch, you have to add a svn new url in the pipeline script from SCM of jenkins ui. Is it redundant? Is there a way to parameterize the svn url? When I build a certain parameter, he Just find the jenkinsfile in that url

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.