• Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • p4-plugin
    • Jenkins 2.138.1
      P4Plugin 1.9.3

      When I try to use 'p4 print' inside P4Groovy (p4-plugin) I get the error:

      ERROR: P4: Task Exception: com.perforce.p4java.exception.ConnectionException: Null output stream in writeText state map
      

      Is this a bug or am I using it wrong?

      Example code:

      pipeline {
        agent { label 'master' }
        stages {
          stage("Repro") {
            steps {
              script {
      	   def p4 = p4(credential: 'JenkinsMaster', workspace: manualSpec(charset: 'none', cleanup: false, name: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}', pinHost: false, spec: clientSpec(allwrite: false, backup: true, changeView: '', clobber: true, compress: false, line: 'LOCAL', locked: false, modtime: false, rmdir: false, serverID: '', streamName: '', type: 'WRITABLE', view: '//depot/Project1/... //jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}/...')))
      	   def myClient = p4.fetch('client', env.P4_CLIENT)
      	   println ("Stream is: " + myClient.get("Stream") )
      	   
              p4.run('print', '-q', '//depot/Project1/VERSION')
              // def version = p4.run('print', '-q', '//depot/Project1/VERSION')
              //echo "version: ${version}"
              }
            }
          }
        }
      }
      

          [JENKINS-54697] How to use 'p4 print' with P4Groovy?

          Karl Wirth added a comment -

          No workaround found. Assigning to dev.

          Karl Wirth added a comment - No workaround found. Assigning to dev.

          Manuel added a comment -

          Running into the same issue, tried to send the output to a file using "-o /Path/to/file" and that way the exception is not thrown but the file is not updated/created with the content of the file.

          Manuel added a comment - Running into the same issue, tried to send the output to a file using "-o /Path/to/file" and that way the exception is not thrown but the file is not updated/created with the content of the file.

          Ian Boudreaux added a comment - - edited

          p4karl any update or workaround on this bug? I am running into this same issue when attempting to run p4 print through P4Groovy and have been unable to find a workaround using P4Groovy.

          Ian Boudreaux added a comment - - edited p4karl any update or workaround on this bug? I am running into this same issue when attempting to run p4 print through P4Groovy and have been unable to find a workaround using P4Groovy.

          Karl Wirth added a comment -

          HI ianboudreaux - I seem to be able to use 'p4 print -o LocalFile.txt //depot/path/file'. For example:

          pipeline {
            agent any 
            stages {
              stage("Repro") {
                steps {
                  script {
                 def p4 = p4(credential: 'JenkinsMaster', workspace: manualSpec(charset: 'none', cleanup: false, name: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}', pinHost: false, spec: clientSpec(allwrite: false, backup: true, changeView: '', clobber: true, compress: false, line: 'LOCAL', locked: false, modtime: false, rmdir: false, serverID: '', streamName: '', type: 'WRITABLE', view: '//depot/Project1/... //jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}/...')))
          
                  // Print out the file to 'LocalFile.txt' in current directory
                  def FILE = sh(script: 'pwd', returnStdout: true).trim() + "/LocalFile.txt";
                  def version = p4.run('print', '-o', FILE, '//depot/f1')
          
                  sh 'cat ' + FILE
                  sh 'rm -f ' + FILE
                  }
                }
              }
            }
          } 

          Karl Wirth added a comment - HI ianboudreaux - I seem to be able to use 'p4 print -o LocalFile.txt //depot/path/file'. For example: pipeline {   agent any    stages {     stage( "Repro" ) {       steps {         script {        def p4 = p4(credential: 'JenkinsMaster' , workspace: manualSpec(charset: 'none' , cleanup: false , name: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}' , pinHost: false , spec: clientSpec(allwrite: false , backup: true , changeView: '', clobber: true , compress: false , line: ' LOCAL ', locked: false , modtime: false , rmdir: false , serverID: ' ', streamName: ' ', type: ' WRITABLE ', view: ' //depot/Project1/... //jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}/...'))) // Print out the file to 'LocalFile.txt' in current directory         def FILE = sh(script: 'pwd' , returnStdout: true ).trim() + "/LocalFile.txt" ;       def version = p4.run( 'print' , '-o' , FILE, ' //depot/f1' )       sh 'cat ' + FILE         sh 'rm -f ' + FILE         }       }     }   } }

          Ian Boudreaux added a comment - - edited

          Thanks p4karl - I was able to reproduce the workaround with your shared snippet, so I am able to get around this issue now!

          Here's the snippet I used:

          String localFilePath = "${env.WORKSPACE}/myFile.txt"
          String depotFilePath = "//depot/Project1/myFile.txt"
          P4.run('print', '-o', localFilePath, depotFilePath)
          def version = (readFile(localFilePath)).trim()
          echo("${version}") 

          Ian Boudreaux added a comment - - edited Thanks p4karl - I was able to reproduce the workaround with your shared snippet, so I am able to get around this issue now! Here's the snippet I used: String localFilePath = "${env.WORKSPACE}/myFile.txt" String depotFilePath = " //depot/Project1/myFile.txt" P4.run( 'print' , '-o' , localFilePath, depotFilePath) def version = (readFile(localFilePath)).trim() echo( "${version}" )

          Karl Wirth added a comment -

          Hi ianboudreaux. Thanks and thanks for the tip about using WORKSPACE. You can see from my ugly code that was the bit I was struggling with .

          Karl Wirth added a comment - Hi ianboudreaux . Thanks and thanks for the tip about using WORKSPACE. You can see from my ugly code that was the bit I was struggling with .

            msmeeth Matthew Smeeth
            p4karl Karl Wirth
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: