plugin support for declarative pipeline

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

plugin support for declarative pipeline

Christian McHugh
Hello everybody,

Recently the saltstack plugin was updated for pipeline support. In working this up, it was important to not just print the return to the console, but to return the value in case it might be needed for further processing. The syntax for doing this looks something like:
stage("run salt") {
    node
("agent1") {
        saltresult
= salt authtype: 'pam', clientInterface: local(arguments: '"sleep 5; tail -1 /etc/hosts"', blockbuild: true, minionTimeout: 32, function: 'cmd.run', jobPollTime: 7, target: '*', targetType: 'glob'), credentialsId: 'b5f40401-01b9-4b27-a5e8-8ae94bc90250', servername: 'http://localhost:8000'
        echo saltresult
   
}
}

This seems to work well, except in the case of the newly released declarative pipeline syntax. I think the syntax for this would be something like:
pipeline {
    agent {label 'agent1'}
    stages {
        stage('run salt') {
            steps {
                output = salt authtype: 'pam', clientInterface: local(arguments: '"sleep 5; ls -la"', function: 'cmd.run', jobPollTime: 16, target: '*', targettype: 'glob'), credentialsId: 'b5f40401-01b9-4b27-a5e8-8ae94bc90250', servername: 'http://localhost:8000'
                echo output
            }
        }
    }
}

Unfortunately this results in an error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 6: Expected a step @ line 6, column 17.
                   output = salt authtype: 'pam', clientInterface: local(arguments: '"sleep 5; ls -la"', function: 'cmd.run', jobPollTime: 16, target: '*', targettype: 'glob'), credentialsId: 'b5f40401-01b9-4b27-a5e8-8ae94bc90250', servername: 'http://localhost:8000'
                   ^

1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1073)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:67)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:430)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:393)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:238)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)

It looks like the error can be avoided by dropping the variable assignment 'output =' bit, however this then makes it impossible to see/print/parse the return from the plugin. Adding in pipeline support made aspects of the plugin much easier, as previously it supported replacing templated options with environment variables (as to support parameterized builds) and saving the salt output into an environment variable. But by supporting pipeline, this all becomes available for free as you can pass in groovy variables and save the return output. However, with the declarative syntax, it again complicates things with its simplicity. How should this be handled?

Thanks much

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/9191d5b4-cc7f-4c9b-86b6-891b72235105%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: plugin support for declarative pipeline

Christian McHugh
Hey all,

With the release of the declarative pipeline syntax, it seems that build steps that return an output are not directly runnable and must be wrapped in a script{} block. Is there a suggested manner of supporting declarative pipelines from a plugin?

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/24fac5c7-c9ab-4721-87c9-19ce2e0076c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: plugin support for declarative pipeline

Christian McHugh
To close this out, I added an option to the plugin to write it's output to a file. Thus you no longer need to use the syntax
output = salt ...

and can instead
salt ... saveFile: true

and later in the pipeline, parse or print the output.

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/43cf3f4e-681c-4a47-a8c6-565bbc6e2f2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...