Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39709

Use SCM extension [$class: 'ScmName'] in Pipeline step

      Given the following code

      lock('checkout') {
          stage('checkout') {
              checkout([$class: 'GitSCM',
                      branches: [[name: branch]],
                      doGenerateSubmoduleConfigurations: false,
                      extensions: [[$class: 'CleanCheckout'], [$class: 'ScmName', name: 'super']],
                      submoduleCfg: [],
                      userRemoteConfigs: [[url: "${gitBaseUrl}/${superRepo}"]]])
      
              def repos = readFile('.gitslave')
              def reposLines = repos.readLines()
              for (line in reposLines) {
                  def repoInfo = line.split(' ')
                  def repoUrl = repoInfo[0]
                  def repoPath = repoInfo[1]
                  def curatedRepoUrl = repoUrl.substring(4, repoUrl.length()-1)
                  def curatedRepoPath = repoPath.substring(1, repoPath.length()-1)
      
                  checkout([$class: 'GitSCM',
                          branches: [[name: branch]],
                          doGenerateSubmoduleConfigurations: false,
                          extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: curatedRepoPath], [$class: 'CleanCheckout'], [$class: 'ScmName', name: curatedRepoPath]],
                          submoduleCfg: [],
                          userRemoteConfigs: [[url: "${gitBaseUrl}/${curatedRepoUrl}"]]])
              }
          }
      }
      
      

      We use $class: 'ScmName', name: curatedRepoPath].

      That is reflected in the SCM list, but not in Pipeline Step. See attached screenshots.

      Would be great if that value was used in the SCM pipeline step.

        1. scm2.png
          scm2.png
          22 kB
        2. scm.png
          scm.png
          47 kB

          [JENKINS-39709] Use SCM extension [$class: 'ScmName'] in Pipeline step

          Julien Pivotto created issue -
          Julien Pivotto made changes -
          Description Original: The `sh` step adds a "Shell Script" step in the Pipeline. However, there could be multiple such steps including steps from various plugins (e.g., Docker), which makes it hard to distinguish the steps. We should perhaps add an optional parameter to sh to specify a name or alias which would then appear in the pipeline steps.

          e.g., the following can be the step for npm which would show as "Shell script: npm" in the pipeline view.
          {code:java}
          sh cmd:"npm install", name: "npm"
          {code}

          New: Given the following code
          {code:groovy}
          lock('checkout') {
              stage('checkout') {
                  checkout([$class: 'GitSCM',
                          branches: [[name: branch]],
                          doGenerateSubmoduleConfigurations: false,
                          extensions: [[$class: 'CleanCheckout'], [$class: 'ScmName', name: 'super']],
                          submoduleCfg: [],
                          userRemoteConfigs: [[url: "${gitBaseUrl}/${superRepo}"]]])

                  def repos = readFile('.gitslave')
                  def reposLines = repos.readLines()
                  for (line in reposLines) {
                      def repoInfo = line.split(' ')
                      def repoUrl = repoInfo[0]
                      def repoPath = repoInfo[1]
                      def curatedRepoUrl = repoUrl.substring(4, repoUrl.length()-1)
                      def curatedRepoPath = repoPath.substring(1, repoPath.length()-1)

                      checkout([$class: 'GitSCM',
                              branches: [[name: branch]],
                              doGenerateSubmoduleConfigurations: false,
                              extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: curatedRepoPath], [$class: 'CleanCheckout'], [$class: 'ScmName', name: curatedRepoPath]],
                              submoduleCfg: [],
                              userRemoteConfigs: [[url: "${gitBaseUrl}/${curatedRepoUrl}"]]])
                  }
              }
          }

          {code}
          We use $class: 'ScmName', name: curatedRepoPath]
          Julien Pivotto made changes -
          Description Original: Given the following code
          {code:groovy}
          lock('checkout') {
              stage('checkout') {
                  checkout([$class: 'GitSCM',
                          branches: [[name: branch]],
                          doGenerateSubmoduleConfigurations: false,
                          extensions: [[$class: 'CleanCheckout'], [$class: 'ScmName', name: 'super']],
                          submoduleCfg: [],
                          userRemoteConfigs: [[url: "${gitBaseUrl}/${superRepo}"]]])

                  def repos = readFile('.gitslave')
                  def reposLines = repos.readLines()
                  for (line in reposLines) {
                      def repoInfo = line.split(' ')
                      def repoUrl = repoInfo[0]
                      def repoPath = repoInfo[1]
                      def curatedRepoUrl = repoUrl.substring(4, repoUrl.length()-1)
                      def curatedRepoPath = repoPath.substring(1, repoPath.length()-1)

                      checkout([$class: 'GitSCM',
                              branches: [[name: branch]],
                              doGenerateSubmoduleConfigurations: false,
                              extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: curatedRepoPath], [$class: 'CleanCheckout'], [$class: 'ScmName', name: curatedRepoPath]],
                              submoduleCfg: [],
                              userRemoteConfigs: [[url: "${gitBaseUrl}/${curatedRepoUrl}"]]])
                  }
              }
          }

          {code}
          We use $class: 'ScmName', name: curatedRepoPath]
          New: Given the following code
          {code:groovy}
          lock('checkout') {
              stage('checkout') {
                  checkout([$class: 'GitSCM',
                          branches: [[name: branch]],
                          doGenerateSubmoduleConfigurations: false,
                          extensions: [[$class: 'CleanCheckout'], [$class: 'ScmName', name: 'super']],
                          submoduleCfg: [],
                          userRemoteConfigs: [[url: "${gitBaseUrl}/${superRepo}"]]])

                  def repos = readFile('.gitslave')
                  def reposLines = repos.readLines()
                  for (line in reposLines) {
                      def repoInfo = line.split(' ')
                      def repoUrl = repoInfo[0]
                      def repoPath = repoInfo[1]
                      def curatedRepoUrl = repoUrl.substring(4, repoUrl.length()-1)
                      def curatedRepoPath = repoPath.substring(1, repoPath.length()-1)

                      checkout([$class: 'GitSCM',
                              branches: [[name: branch]],
                              doGenerateSubmoduleConfigurations: false,
                              extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: curatedRepoPath], [$class: 'CleanCheckout'], [$class: 'ScmName', name: curatedRepoPath]],
                              submoduleCfg: [],
                              userRemoteConfigs: [[url: "${gitBaseUrl}/${curatedRepoUrl}"]]])
                  }
              }
          }

          {code}
          We use {{$class: 'ScmName', name: curatedRepoPath]}}.

          That is reflected in the SCM list, but not in Pipeline Step. See attached screenshots.

          Would be great if that value was used in the SCM pipeline step.
          Julien Pivotto made changes -
          Attachment New: scm.png [ 34823 ]
          Julien Pivotto made changes -
          Attachment Original: scm.png [ 34823 ]
          Julien Pivotto made changes -
          Attachment New: scm.png [ 34824 ]
          Julien Pivotto made changes -
          Attachment New: scm2.png [ 34825 ]
          James Dumay made changes -
          Component/s New: blueocean-plugin [ 21481 ]
          James Dumay made changes -
          Link New: This issue duplicates JENKINS-37324 [ JENKINS-37324 ]
          James Dumay made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

            Unassigned Unassigned
            roidelapluie Julien Pivotto
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: