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

"When { branch: }" does not work inside of podTemplate's node, stage or container

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • kubernetes-plugin
    • Jenkins 2.387.3
      Kubernetes
      Version3937.vd7b_82db_e347b_

      Image jenkins/jenkins:2.387.3

      "java.lang.NoSuchMethodError: No such DSL method 'when' found among steps" is shown if I want to use the when directive. This way making impossible to work with Multibranch SCM projects.

      example:

      ```
      podTemplate(
          label: 'jenkins-jenkins-agent', cloud: 'kubernetes', namespace: 'default',
          yaml: """    
        spec:
            hostAliases:
            - ip: xx.xxx.xxx.xx
              hostnames:
              - "xxxxx"
              - "xxxx"
      """,
          nodeSelector: 'Nodegroup=xxxx',
          envVars : [
              envVar(key: 'ECR_REPO', value: 'dff/staging/jenkins'),
              envVar(key: 'ECR_ENDPOINT', value: 'xxxxxxxx'),
              envVar(key: 'CLUSTER_NAME', value: 'xxxxxx'),
              envVar(key: 'BUILD_REPO', value: 'cloud-jenkins'),
              envVar(key: 'K8S_YAML_REPO', value: 'cloud-k8s-apps'),
              envVar(key: 'BUILD_NUMBER', value: "${BUILD_NUMBER}"),
              envVar(key: 'BRANCH_NAME', value: "${BRANCH_NAME}"),
              envVar(key: 'AWS_DEFAULT_REGION', value: 'us-east-2'),
              secretEnvVar(key: 'AWS_ACCESS_KEY_ID', secretName: 'aws-secret', secretKey: 'AWS_ACCESS_KEY_ID'),  
              secretEnvVar(key: 'AWS_SECRET_ACCESS_KEY', secretName: 'aws-secret', secretKey: 'AWS_SECRET_ACCESS_KEY')
          ],
          containers: [
              containerTemplate(
                  name: 'unzip',
                  image: 'xxxxxx',
                  ttyEnabled: true,
                  command: 'sleep',
                  args: '9999'
              )
          ],
          volumes: [
              configMapVolume(configMapName: 'docker-config', mountPath: '/root/.docker')
          ],
      ) {
          node('jenkins-jenkins-agent') {
              stage('Preparation') {
                  when

      {                 branch 'staging'             }

                  container('unzip') {
                      git branch: 'staging', url: 'https://socgit.advantest.com/bitbucket/scm/acs-datalake/cloud-jenkins.git', credentialsId: 'xxxx'
                      sh """
                          git branch -D ${BRANCH_NAME} || true
                  """
                  }
              }
          }
      }
      ```
       

      Is there any other way to develop Multibranch SCM pipelines using the kubernetes plugin??

            Unassigned Unassigned
            joaoaguilera João
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: