Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

options {skipDefaultCheckout()}

Scenario 1 - No load rules in the second checkout

1. Checkout only the JenkinsFile using minimal load rules. That is, configure  load rules  in the pipeline job's SCM configuration to load just the JenkinsFile and nothing else. This can be done for build definition, repository workspace, snapshot and stream configuration. This keeps the loading time very minimal in the master.

2. Inside the JenkinsFile, if you want to checkout on a slave or master again (not under pipeline@script folder), load the snapshot. For build definition and personal builds triggered from RTC, checkout the build definition once again.

For Build Definition

node ("slavexyz") {
if ("${env.personalBuild}" == "true") { // This is true when a personal build is started from RTC.
          echo "Checking out the build definition in node"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildDefinition: '<build definition used in Pipeline script from SCM>', customizedSnapshotName: '', value: 'buildDefinition'], overrideGlobal: false timeout: 480'])
      } else { // Otherwise we checkout the snapshot created by the Pipeline Script from SCM's checkout.
          echo "Checking out a snapshot in node"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildSnapshot: "${env.team_scm_snapshotUUID}", buildSnapshotContext: [snapshotOwnerType: 'none'], currentSnapshotOwnerType: 'none', loadDirectory: '.', value: 'buildSnapshot']], timeout: 480])
      }
   }
}

For Stream:
node ("slavexyz") {
          echo "Checking out a snapshot in node from stream configuration"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildSnapshot: "${env.team_scm_snapshotUUID}", buildSnapshotContext: [snapshotOwnerType: 'none'], currentSnapshotOwnerType: 'none', loadDirectory: '.', value: 'buildSnapshot']], timeout: 480])
}

For Repository workspace:
node ("slavexyz") {
         echo "Checking out a snapshot in node from snapshot configuration"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildSnapshot: "${env.team_scm_snapshotUUID}", buildSnapshotContext: [snapshotOwnerType: 'none'], currentSnapshotOwnerType: 'none', loadDirectory: '.', value: 'buildSnapshot']], timeout: 480])
}

For snapshot:
node ("slavexyz") {
          echo "Checking out a snapshot in node from snapshot configuration"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildSnapshot: "${env.team_scm_snapshotUUID}", buildSnapshotContext: [snapshotOwnerType: 'none'], currentSnapshotOwnerType: 'none', loadDirectory: '.', value: 'buildSnapshot']], timeout: 480])
}


Scenario 2 - Load rules in the second checkout

1. Checkout the JenkinsFile using minimal load rules. That is, configure  load rules  in the pipeline job's SCM configuration to load just the JenkinsFile and nothing else. This can be done for build definition, repository workspace, snapshot and stream configuration. This keeps the loading time very minimal in the master.

2. Inside the JenkinsFile, if you want to checkout on a slave or master again (in a different path), configure different load rules that will load the content required for the build. Note that you can parameterize the load rules using Jenkins Job property instead of directly providing the value.

Note: For Build definition, personal builds are not supported when load rules or components to include/exclude are used in Jazz SCM configuration in the build defintion. Therefore, the following sample will error out when it sees a personal build

Note: You can use load rules or components to exclude. In the sample below, I am assuming load rules. You can substitute loadPolicy with useComponenLoadConfig and provide components to exclude.


For Build Definition
node ("slavexyz") {
if ("${env.personalBuild}" == "true") { // This is true when a personal build is started from RTC.
         error "Personal builds not supported when using load rules or components to include/exclude"
      } else { // Otherwise we checkout the snapshot created by the Pipeline Script from SCM's checkout.
          echo "Checking out a snapshot in node"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildSnapshot: "${env.team_scm_snapshotUUID}", buildSnapshotContext: [snapshotOwnerType: 'none'], currentSnapshotOwnerType: 'none', loadDirectory: '.', value: 'buildSnapshot' loadPolicy: 'useLoadRules', pathToLoadRuleFile: 'Comp1/loadrules/build.loadRule'], timeout: 480])
      }
   }
}

Stream:
node ("slavexyz") {
          echo "Checking out a snapshot in node from stream configuration"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildSnapshot: "${env.team_scm_snapshotUUID}", buildSnapshotContext: [snapshotOwnerType: 'none'], currentSnapshotOwnerType: 'none', loadDirectory: '.', value: 'buildSnapshot', loadPolicy: 'useLoadRules', pathToLoadRuleFile: 'Comp1/loadrules/build.loadRule'], timeout: 480])
}

For Repository workspace:
node ("slavexyz") {
          echo "Checking out a snapshot in node from repository workspace configuration"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildSnapshot: "${env.team_scm_snapshotUUID}", buildSnapshotContext: [snapshotOwnerType: 'none'], currentSnapshotOwnerType: 'none', loadDirectory: '.', value: 'buildSnapshot', loadPolicy: 'useLoadRules', pathToLoadRuleFile: 'Comp1/loadrules/build.loadRule'], timeout: 480])
}

For snapshot:
node ("slavexyz") {
          echo "Checking out a snapshot in node from snapshot configuration"
          checkout([$class: 'RTCScm', avoidUsingToolkit: false, buildType: [buildSnapshot: "${env.team_scm_snapshotUUID}", buildSnapshotContext: [snapshotOwnerType: 'none'], currentSnapshotOwnerType: 'none', loadDirectory: '.', value: 'buildSnapshot', loadPolicy: 'useLoadRules', pathToLoadRuleFile: 'Comp1/loadrules/build.loadRule'], timeout: 480])
}

When you want to load new content in every agent (including the master) after the initial Pipeline script from SCM checkout

When you don't set skipDefaultCheckout(true), then by default, every time an agent directive is used, a checkout happens based on the SCM configuration in Pipeline from SCM. You can also run additional You can add new checkout steps with different options (like loadrules, or load directory) as required by directly referencing the build definition, stream or build workspace in the JenkinsFile, instead of loading from the last snapshot. If you have a build definition configuration and the build is triggered from RTC, then multiple checkouts on the same build definition will reuse the build result instead of creating new ones. This is different from how it works when the build is triggered from Jenkins where each checkout step with the same build definition will still create new build results.

Considerations when using declarative pipeline

If you are using declarative pipeline, then every agent directive will cause a checkout to happen in that agent using the same configuration asPipeline Script from SCM. When using a build definition, stream or workspace configuration, this will cause an accept to happen in each of those cases, leading to different content being loaded in each agent. In the case of build definition, an additional build result will be created if the build is triggered from Jenkins. This may or may not be what you want. If you want to prevent the extra checkout for every agent directive, add the options directive below the agent directive with skipDefaultCheckout(true)

options {skipDefaultCheckout(true)}

Generating Pipeline Snippet for Team Concert Plugin from Snippet Generator

...