Resending from this morning, which didn't go through, see below.

2017-04-10 8:23 GMT+02:00 Stephen Connolly <[email protected]>
:

>
> On Mon 10 Apr 2017 at 06:02, niristotle okram <[email protected]>
> wrote:
>
>> I have seen that mentioned somewhere in the past. But i am baffled as to
>> why things works in the master and fails in the slave/agent.
>>
>> Can anyone spot where i am faulting. this have owned me for days now :(
>> ... i am trying to generate an XML file. based on the data provided by a
>> JSON file.
>>
>>
>> The pipeline snippet is
>>
>> *import groovy.xml.**
>> *import groovy.json.JsonSlurper*
>>
>> *node('slave1') {*
>> *  deleteDir()*
>>
>> *  stage('Checkout') {*
>> *    checkout([$class: 'GitSCM', branches: [[name: '*/master']],
>> doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [],*
>> *    userRemoteConfigs: [[credentialsId:
>> 'b27f7cb2-efa8-496a-90d8-825b9332bf44', url: '[email protected]']]])*
>> *  }*
>>
>> *  writeFile file: "MyFile.XML", text: GenerateXML()    //calling the
>> method to generate the XML*
>>
>
>> *  println "Generated the manifest XML"*
>> *}*
>>
>>
>> *@NonCPS*
>> *def GenerateXML() {*
>> *  /**
>> *  parsing the obj.json file*
>> *  */*
>> *  def currentws = pwd()*
>> *  println currentws*
>> *  def jsonSlurper = new JsonSlurper();  *
>> *  //def fileReader = new BufferedReader(new
>> FileReader("${currentws}/objects.json"))  //the file location need to
>> change in the actual implementation*
>>
>
> This won't work as groovy always executes on the master. You need to use
> FilePath to get the remote file
>

Yes, also, avoid IMO doing fancy XML/JSON processing in Java/Groovy. See
Pipeline as an orchestration tool with basic/no programming capabilities
and delegate things to CLI tools and so on.
If you wish to do more high level things, then possibly have a look at
writing a plugin.

In general, keep your pipeline code as stupid as possible. Also, using
external tools will make it easier to test/reuse from your own local dev
env.



>
> *  def fileReader = readFile "${currentws}/objects.json"  // ^^avoided the
>> above line to use the pipeline DSL *
>>
>
> Afaik you can put CPS calls inside nonCPS
>

No, it's not supported.

"You may not call regular (CPS-transformed) methods, or Pipeline steps,
from a @NonCPS method"

https://github.com/jenkinsci/workflow-cps-plugin/#technical-design


[snip]

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS4u8fp1_NFrNKCeop933Gier_f9MuhH1oMo480rHQ5z5A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to