Search code examples
jenkinsjenkins-workflowjenkins-pipelinejenkins-2

Specify properties once, not twice


When I have a pipeline in Jenkins 2 multi-branch project like :

node {
  stage 'Stage Checkout'

  // Checkout code from repository and update any submodules
  //checkout scm
  git credentialsId: 'myId', url: 'https://gitlab.mycompany.com'

  stage 'Stage Build'
  echo "My branch is: ${env.BRANCH_NAME}"
}

I do need to specify the credentialsId and URL twice:

  1. in the Jenkinsfile like above
  2. in the Jenkins UI enter image description here

It seems to be redundant to specify these two properties twice. Is there a possibility to specify them only once?


Solution

  • You can use:

    checkout scm
    

    Instead of git command, checkout scm will use the data provided in the Jenkins configuration.