Re: Load properties from a properties file and make it available anywhere in the pipeline

2017-05-03 Thread Robert Sandell
I've gotten similar requests before to have some type of similar
behavior/mode as readTrusted, so maybe it gets implemented sometime in the
future.

/B

On Wed, May 3, 2017 at 2:38 PM, ishan jain  wrote:

> Thanks a lot Robert, that solved my problem. You are right, i should not
> whitelist those methods just load properties fille. Your plugin seems to be
> great, i will invest some time in learning other methods as well.
>
> Also, do you think i can load the properties outside of a stage somehow ?
> I hate to have a separate stage for such preparation stuff.
>
>
> On Wednesday, 3 May 2017 12:24:02 UTC+2, Robert Sandell wrote:
>>
>> The File constructor is blacklisted so that users don't try to do the
>> mistake that you are doing.
>> The pipeline code is running on the master (only the steps themselves are
>> actually running on the agent), so when you create a new file pointing it
>> to $workspace it is most likely not there on the master unless you are
>> actually running on the master agent.
>> For these more advanced scenarios I created the Pipeline Utility Steps
>> plugin
>> 
>> that has among others a readProperties
>> 
>> step.
>>
>> /B
>>
>> On Tuesday, May 2, 2017 at 5:57:32 PM UTC+2, ishan jain wrote:
>>>
>>> Hi all,
>>>
>>> My requirement is simple, i just want to externalize some 'values' to
>>> make my Jenkinsfile more re usable and for this i need to* load the
>>> properties from a file which is going to be right next to Jenkinsfile, and
>>> make sure that these properties are available anywhere in the code*. I
>>> am still new to groovy and Jenkins code but never thought such a simple
>>> thing would be so difficult. I enabled some methods in script security
>>> plugin but the following code always pose error or print null. I have tried
>>> multiple combinations and the below code is just one of them
>>>
>>> properties = null
>>>
>>> @NonCPS
>>> def loadProperties() {
>>> checkout scm
>>> File propertiesFile = new File('${workspace}/pipeline.properties')
>>> propertiesFile.withInputStream {
>>> properties.load(propertiesFile)
>>> }
>>> }
>>>
>>> pipeline {
>>> agent none
>>> stages {
>>>
>>> stage ('prepare') {
>>> agent any
>>> steps {
>>> script {
>>> loadProperties()
>>> echo "${properties['repo']}"
>>> }
>>> }
>>> }
>>> stage('Build') {
>>>
>>> agent any
>>> steps {
>>> sh 'echo ${properties.repo}'
>>> }
>>> }
>>> }
>>> }
>>>
>>>
>>>
>>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Jenkins Users" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/jenkinsci-users/8DJwV2laHCM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> jenkinsci-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/f054f784-9126-406a-8de7-baabac9f6998%40googlegroups.
> com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Robert Sandell
*Software Engineer*
*CloudBees Inc.*

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CALzHZS1XWcxmWENCQNvbEgcOfJ3tP_GVSC_0Byq5QUYYU5D4cQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Load properties from a properties file and make it available anywhere in the pipeline

2017-05-03 Thread ishan jain
Thanks a lot Robert, that solved my problem. You are right, i should not 
whitelist those methods just load properties fille. Your plugin seems to be 
great, i will invest some time in learning other methods as well.

Also, do you think i can load the properties outside of a stage somehow ? I 
hate to have a separate stage for such preparation stuff.

On Wednesday, 3 May 2017 12:24:02 UTC+2, Robert Sandell wrote:
>
> The File constructor is blacklisted so that users don't try to do the 
> mistake that you are doing.
> The pipeline code is running on the master (only the steps themselves are 
> actually running on the agent), so when you create a new file pointing it 
> to $workspace it is most likely not there on the master unless you are 
> actually running on the master agent.
> For these more advanced scenarios I created the Pipeline Utility Steps 
> plugin 
>  
> that has among others a readProperties 
> 
>  
> step.
>
> /B
>
> On Tuesday, May 2, 2017 at 5:57:32 PM UTC+2, ishan jain wrote:
>>
>> Hi all,
>>
>> My requirement is simple, i just want to externalize some 'values' to 
>> make my Jenkinsfile more re usable and for this i need to* load the 
>> properties from a file which is going to be right next to Jenkinsfile, and 
>> make sure that these properties are available anywhere in the code*. I 
>> am still new to groovy and Jenkins code but never thought such a simple 
>> thing would be so difficult. I enabled some methods in script security 
>> plugin but the following code always pose error or print null. I have tried 
>> multiple combinations and the below code is just one of them
>>
>> properties = null
>>
>> @NonCPS
>> def loadProperties() {
>> checkout scm
>> File propertiesFile = new File('${workspace}/pipeline.properties')
>> propertiesFile.withInputStream {
>> properties.load(propertiesFile)
>> }
>> }
>>
>> pipeline {
>> agent none
>> stages {
>> 
>> stage ('prepare') {
>> agent any
>> steps {
>> script {
>> loadProperties()
>> echo "${properties['repo']}"
>> }
>> }
>> }
>> stage('Build') {
>> 
>> agent any
>> steps {
>> sh 'echo ${properties.repo}'
>> }
>> }
>> }
>> }
>>
>>
>>
>>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/f054f784-9126-406a-8de7-baabac9f6998%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Load properties from a properties file and make it available anywhere in the pipeline

2017-05-03 Thread Robert Sandell
The File constructor is blacklisted so that users don't try to do the 
mistake that you are doing.
The pipeline code is running on the master (only the steps themselves are 
actually running on the agent), so when you create a new file pointing it 
to $workspace it is most likely not there on the master unless you are 
actually running on the master agent.
For these more advanced scenarios I created the Pipeline Utility Steps 
plugin 
 
that has among others a readProperties 

 
step.

/B

On Tuesday, May 2, 2017 at 5:57:32 PM UTC+2, ishan jain wrote:
>
> Hi all,
>
> My requirement is simple, i just want to externalize some 'values' to make 
> my Jenkinsfile more re usable and for this i need to* load the properties 
> from a file which is going to be right next to Jenkinsfile, and make sure 
> that these properties are available anywhere in the code*. I am still new 
> to groovy and Jenkins code but never thought such a simple thing would be 
> so difficult. I enabled some methods in script security plugin but the 
> following code always pose error or print null. I have tried multiple 
> combinations and the below code is just one of them
>
> properties = null
>
> @NonCPS
> def loadProperties() {
> checkout scm
> File propertiesFile = new File('${workspace}/pipeline.properties')
> propertiesFile.withInputStream {
> properties.load(propertiesFile)
> }
> }
>
> pipeline {
> agent none
> stages {
> 
> stage ('prepare') {
> agent any
> steps {
> script {
> loadProperties()
> echo "${properties['repo']}"
> }
> }
> }
> stage('Build') {
> 
> agent any
> steps {
> sh 'echo ${properties.repo}'
> }
> }
> }
> }
>
>
>
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/b1a89c6f-0c53-4e00-af25-80a052f7ac5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.