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

how to use p4groovy in declarative pipeline

    Details

    • Similar Issues:

      Description

      Hi,

      How can I use p4 groovy in declarative pipeline?

      Karl Wirth, you told me that I can use below syntax, but I can't use this.

       

      pipeline {
        agent {
          kubernetes {
           label 'test'
           yamlFile 'test.yaml'
          }
        }
        options {
          skipDefaultCheckout()
        }
        stages {
          stage('Run Test') {
            steps {
              container(name: 'test', shell: '/bin/bash') {
                p4 credential: 'p4_10.251.245.74_1667_perforce', workspace: templateSpec(charset: 'utf8', format: 'jenkins-${JOB_NAME}-${BUILD_ID}-${NODE_NAME}', pinHost: false, templateName: 'TEMPLATE')
                // and how to use p4.run('client', '-o') for example
              }
            }
          }
        }
      }
      

        Attachments

          Activity

          Hide
          p4karl Karl Wirth added a comment -

          Hi Hokwang Lee. P4Groovy is scripted pipeline code so please try a 'script' block as described in:

          https://jenkins.io/doc/book/pipeline/syntax/

          For example:

          pipeline {
            agent { label 'master' }
            stages {
              stage("Repro") {
                steps {
                       script {           
                          def ws = [$class: 'StreamWorkspaceImpl',charset: 'none', format: 'test', pinHost: false,streamName: '//streams/main']     
                          def p4 = p4(credential: 'JenkinsMaster', workspace: ws)
                          def output = p4.run('info')
                          output[0].each{key, value -> println ("${key} = ${value}");}
                          }
                      }
                  }
              } 
          }
          
          Show
          p4karl Karl Wirth added a comment - Hi Hokwang Lee . P4Groovy is scripted pipeline code so please try a 'script' block as described in: https://jenkins.io/doc/book/pipeline/syntax/ For example: pipeline { agent { label 'master' } stages { stage( "Repro" ) { steps { script { def ws = [$class: 'StreamWorkspaceImpl' ,charset: 'none' , format: 'test' , pinHost: false ,streamName: ' //streams/main' ] def p4 = p4(credential: 'JenkinsMaster' , workspace: ws) def output = p4.run( 'info' ) output[0].each{key, value -> println ( "${key} = ${value}" );} } } } } }
          Hide
          p4karl Karl Wirth added a comment -

          Hi Hokwang Lee - Did the above snippet help to solve the problem?

          Show
          p4karl Karl Wirth added a comment - Hi Hokwang Lee - Did the above snippet help to solve the problem?
          Hide
          luckyhorang Hokwang Lee added a comment -

          Hi, Karl Wirth

           

          Thanks for your help. 

           

          You can close this issue.

          Show
          luckyhorang Hokwang Lee added a comment - Hi, Karl Wirth   Thanks for your help.    You can close this issue.
          Hide
          p4karl Karl Wirth added a comment -

          Hi Hokwang Lee - Thanks.

          Show
          p4karl Karl Wirth added a comment - Hi Hokwang Lee - Thanks.

            People

            • Assignee:
              p4karl Karl Wirth
              Reporter:
              luckyhorang Hokwang Lee
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: