0

This looks like very basic question about Jenkins usage.

I have Jenkinsfile located in root folder of my Subversion repository tree. There are many branches (versions/tags) of the product - everywhere is the same Jenkinsfile. So far very basic setup, I suppose.

I need to provide some steps with current Subversion repository branch/url. There are some similar questions like this or this, but none is working solution for Subversion.

pipeline {
  agent { label 'master' }
  stages {
    stage("test") {
      steps {
        echo "Start pipeline "
        // commented-out = not working
        //echo scm.getUserRemoteConfigs()
        //echo scm
        script {
            println "Current svn url/branch: "//??? + scm.getUserRemoteConfigs()[0].getUrl()
        }
      }
    }
  }
}
LiborStefek
  • 400
  • 4
  • 16

1 Answers1

1

It will be like this

pipeline {
  agent any;
  stages  {
    stage('test'){
      steps {
        script {
          def s = checkout scm;
          if      (s.GIT_URL != null) {
            print s.GIT_URL
            print s.GIT_BRANCH
            print s.GIT_COMMIT
          }
          else if (s.SVN_URL != null) {
            print s.SVN_REVISION
            print s.SVN_REVISION_1
            print s.SVN_URL
            print s.SVN_URL_1
          }
        }
      }
    }
  }
}

Note- This works fine with GIT and SVN, but a bit differently.

LiborStefek
  • 400
  • 4
  • 16
Samit Kumar Patel
  • 1,932
  • 1
  • 13
  • 20