ok thanks, that seems to work as far as reading the properties file, but
then fails when I try to echo the variable:

 def props = readProperties file: 'project.properties'
 def Var1= props['RELEASE']
 def Var2= props['SOFTWARE.VERSION']

echo "Var1=" Var1
echo "Var2=" Var2

java.lang.NullPointerException: Cannot get property 'Var1' on null object


On 21 September 2016 at 17:12, Phillip Campbell <[email protected]>
wrote:

> Here's a snippet from a Jenkinsfile in a pre-2.0  pipeline job that I use
> to read an existing build.properties file in the workspace so that the
> Jenkinsfile can use the properties.  I haven't tried this in 2.0 pipeline
> yet.
>
>         if (!fileExists('build.properties')){            echo 'No build 
> properties.'      exit         }        def props = readProperties file: 
> 'build.properties'   /*       * From build.properties file    */        def 
> Var1= props["SOME_PROPERTY"]        def Var2= props["ANOTHER_PROPERTY"]
>
>
> On Wed, Sep 21, 2016 at 8:22 AM, Pete Singleton <[email protected]>
> wrote:
>
>> Hi, I'm having exactly the same issue (having only started with Jenkins
>> 2.0 in the last couple of days).  I've tried the Pipeline Utility, tried
>> the EnvInject plugin, also tried opening the file using Groovy file
>> operations, no success!  Did you manage to solve this??
>>
>> On Thursday, 8 September 2016 21:50:01 UTC+1, Ian Cotton wrote:
>>>
>>> Thanks Jerome. Unfortunately this doesn't help me much. The properties
>>> file I need to load already exists and is in use by various build scripts.
>>> I assume I need to create an EnvInjectJobProperty object and set the
>>> appropriate property on it. I'll give that a try.
>>>
>>> On Wed, Sep 7, 2016 at 7:07 PM <[email protected]> wrote:
>>>
>>>> Not sure about the Java properties file, but I succeed by doing a
>>>> .groovy file if that's interest you (probably not, but here it is if
>>>> someone need it, it's unsafe but in controlled env it doesn't matter):
>>>>
>>>> *Jenkinsfile*
>>>> def my_var = evaluate(new File("myEnv.groovy"));
>>>> bat "\"${my_var.python_2_exe}\" myscript.py"
>>>> ...
>>>>
>>>> *myEnv.groovy*
>>>> def rv= [:]
>>>>
>>>> rv['mercurial_url'] = 'http://mercurial.buildserver/'
>>>> rv['python_2_exe'] = "c:\\Python27\\python.exe"
>>>> ...
>>>> return rv;
>>>>
>>>> I put the .groovy file on the build machine jenkins folder, so the
>>>> Jenkinsfile from the repos can work with vars from any of our build
>>>> machines or network emplacement.
>>>>
>>>> --
>>>> 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/ms
>>>> gid/jenkinsci-users/1a03bb2f-5022-4005-ab10-5e3146aebcd1%40g
>>>> ooglegroups.com
>>>> <https://groups.google.com/d/msgid/jenkinsci-users/1a03bb2f-5022-4005-ab10-5e3146aebcd1%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> 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/ms
>> gid/jenkinsci-users/fcf3de22-08c3-47e2-b996-1d0bd85f28ed%
>> 40googlegroups.com
>> <https://groups.google.com/d/msgid/jenkinsci-users/fcf3de22-08c3-47e2-b996-1d0bd85f28ed%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> 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/OV9h0q_FGfQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/CAAYHPVij13azLVN%2BwkQfeGG_
> ExE6eUqGE1A4cL9Dg-zvwtXK0A%40mail.gmail.com
> <https://groups.google.com/d/msgid/jenkinsci-users/CAAYHPVij13azLVN%2BwkQfeGG_ExE6eUqGE1A4cL9Dg-zvwtXK0A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CAG7ZcNsW5TAbKo1J%3Dm77x9F_FQYcNzh5ndQWHe%2Bo3s5wYtwmGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to