Search code examples
jenkinsgroovyclearcasecleartool

How to use fmt_case in jenkins groovy?


I am trying to use the below command in Jenkins pipeline in Groovy Sandbox.

descr -fmt "%[rec_bls]CXp" stream:stream_name@\my_vob  

While the command runs properly if executed from windows cmd, but throws below error while executing in a Jenkins stage.

Running batch script    
path_to_workspace>cleartool describe -fmt 'stream_name@\my_vob
cleartool: Error: Object selector required.
Usage: describe -graphical pname …
...
…

Below is the Jenkins stage snippet :

        stage ('Test') {            
        agent {label 'Jenkins_Label'}           
        steps{          
            bat """             
    cleartool describe -fmt "%[rec_bls]CXp" stream:stream_name@\\vob_name
         """            
         }
       }

Solution

  • Check first if this is because of the -fmt "%[rec_bls]CXp", whose quotes are incorrectly interpreted in the Jenkins bat shell session.

    For instance:

      stage ('Test') {            
        agent {label 'Jenkins_Label'}           
        steps{          
            bat """             
    cleartool describe -l stream:stream_name@\\vob_name
         """            
         }
       }
    

    If that works, try and see how to add those quotes.
    For instance:

    cleartool describe -fmt """%[rec_bls]CXp""" stream:stream_name@\\vob_name
    # or
    cleartool describe -fmt \"%[rec_bls]CXp\" stream:stream_name@\\vob_name
    

    If the '%' is the issue, escape it:

    cleartool describe -fmt \"%%[rec_bls]CXp\" stream:stream_name@\\vob_name
    

    That will prevent the bat session to interpret it as a variable environment.