[Config File Provider Plugin] how to use plugin in pipeline

1,640 views
Skip to first unread message

Evgeniy Maksimenko

unread,
Dec 17, 2016, 3:29:18 PM12/17/16
to Jenkins Users
This code works as expected

file ='fileId'
node
{
    configFileProvider
([configFile(fileId: file, variable: 'propertiesFile')]) {
        echo
"$propertiesFile"
   
}
}

I tried to move it to class

class Runner implements Serializable {
   
def steps
   
Runner(steps) {
           
this.steps = steps
   
}
   
void createParametersYaml() {
        steps
.node {
            steps
.configFileProvider([steps.configFile(fileId: file, variable: 'propertiesFile')]) {
                steps
.echo "$propertiesFile"
           
}
       
}
   
}
}
new Runner(steps).createParametersYaml()

and get error
groovy.lang.MissingPropertyException: No such property: propertiesFile for class: Runner
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
	at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:243)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:52)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:308)
	at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:28)
	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
	at Runner.createParametersYaml(WorkflowScript:15)
	at ___cps.transform___(Native Method)

How can I fix this?

Message has been deleted
Message has been deleted
Message has been deleted

Evgeniy Maksimenko

unread,
Jan 28, 2017, 2:54:57 PM1/28/17
to Jenkins Users
up

Björn Pedersen

unread,
Jan 30, 2017, 4:03:13 AM1/30/17
to Jenkins Users
Hi,

this is a groovy feature:

The plugin sets propertiesFile in the (implicitly generated) script class, so it is not visible from your class.
See http://stackoverflow.com/questions/15619216/groovy-scope-how-to-access-script-variable-in-a-method for details.

Björn

Am Samstag, 28. Januar 2017 20:54:57 UTC+1 schrieb Evgeniy Maksimenko:
up

Alejandro Moncayo

unread,
Jan 29, 2019, 5:17:14 PM1/29/19
to Jenkins Users
After searching around for examples and not finding good ones, I have this one:

A sample text properties file with this data:
property1=value1
property2=value2
property3=value3

and my pipeline looks like:
///////////////////////////
//Pipeline starts here
/////////////////
import groovy.io.FileType
import groovy.json.*
import hudson.model.Result
import java.util.Properties

node {
    Properties properties = new Properties()
    
    configFileProvider([configFile(fileId: 'asq213', variable: 'fileLocation')]) {
        File propertiesFile = new File("${env.fileLocation}")
        properties.load(propertiesFile.newDataInputStream())
    }

        println properties.property1
        println properties.property2
        println properties.property3
}

///////////////////////////
//Pipeline ends here
/////////////////

Arnaud bourree

unread,
Feb 2, 2019, 8:52:30 AM2/2/19
to jenkins...@googlegroups.com
Hi,

Does properties file format mandatory for you? 
If not, you can try yaml format and readYaml will provide you object.

Arnaud. 

--
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 jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/31936bde-2b08-499a-b75f-b89aae987684%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages