cant get windows env variables into a jobDSL mavenJob

37 views
Skip to first unread message

TJC

unread,
Sep 7, 2017, 12:52:09 PM9/7/17
to job-dsl-plugin

I have a mavenJob on a windows box that looks like this below.

I have the windows env vars I want to use on the system, as the script output shows me but...

I cant seem to use them where I need to ...

Any ideas ?


mavenJob(JobName.INTEGR_X_SANITY_TESTS_JOB.name) {

    description sqmCtx.description('Sanity test suite for X GUI.')

    customWorkspace('$JENKINS_HOME/workspace/x-ci-sanity')   <<< here we can somehow “see” JENKINS_HOME as we expect to and …

    //

    with xCtx.slaveSetupMaven()

    logRotator { daysToKeep(30) }

    //

    goals('clean test')

    rootPOM('$JENKINS_HOME/workspace/x-ci-sanity/pom.xml')

    mavenOpts('-Xmx2048m -Xms512m')

    localRepository(LocalRepositoryLocation.LOCAL_TO_WORKSPACE)

 

    environmentVariables {    <<< … all the parms we need are visible in a script as *windows* variables as this echo works …

        script('''

           echo "JENKINS_HOME = [%JENKINS_HOME%]"

           echo "CLUSTER = [%CLUSTER%]"

           echo "X_JBOSS = [%X_JBOSS%]"

           echo "X_ENGINE_SERVER = [%X_ENGINE_SERVER%]"

        ''')

    }

 

    parameters xCtx.njGuiParam('firefox', 'xCI-tests', “https://%X_JBOSS%/sqm”, “%X_ENGINE_SERVER%”);   <<< … but we can’t seem to use them in the jobDSL parameters



TJC

unread,
Sep 7, 2017, 1:07:35 PM9/7/17
to job-dsl-plugin
to clarify a bit, njGuiParam is a Closure of 4 stringParam varaibles defined in out Context class, in this case xCtx

    @JobDslContext(BuildParametersContext)
    Closure njGuiParam(String browser, String xml, String url, String db_server) {
        return {
            stringParam 'Browser', browser, 'parameter for browser driver';
            stringParam 'suiteXmlFile', xml, 'test suite name';
            stringParam 'URL', url, 'GUI URL';
            stringParam 'DB_SERVER', db_server, 'DB Server or SQM ENGINE Server for tests';

Daniel Spilker

unread,
Sep 7, 2017, 3:51:07 PM9/7/17
to job-dsl...@googlegroups.com
Windows shell variable expansion does not work Groovy strings.

To get the value of operating system environment variables, use this method:
http://docs.oracle.com/javase/7/docs/api/java/lang/System.html#getenv(java.lang.String)

Notice that operating system environment variables may differ on Jenkins master and build agents. Job DSL scripts are always executed on Jenkins master.

Also see the Job DSL wiki about Jenkins environment variable (which are different from operating system environment variables):
https://github.com/jenkinsci/job-dsl-plugin/wiki/User-Power-Moves#access-the-jenkins-environment-variables

And finally see the Groovy docs about string interpolation, which must not be confused with shell variable expansion:
http://docs.groovy-lang.org/latest/html/documentation/#_string_interpolation

Daniel




--
You received this message because you are subscribed to the Google Groups "job-dsl-plugin" group.
To unsubscribe from this group and stop receiving emails from it, send an email to job-dsl-plugin+unsubscribe@googlegroups.com.
To post to this group, send email to job-dsl-plugin@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/job-dsl-plugin/9ed6584e-6463-4241-a883-f4883331f70a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

TJC

unread,
Sep 8, 2017, 2:05:02 PM9/8/17
to job-dsl-plugin
When you say: "Job DSL scripts are always executed on Jenkins master."
How is this possible to see environment variables from windows when that box is the slave ?

I tried the getenv approach, but got no values for the variables ...

Here we modified the njGuiParam closure to look for env vars and substitute them ...

    @JobDslContext(BuildParametersContext)

    Closure njGuiParam(String browser, String xml, String url='x', String dbServer='x') {

        def (String newUrl, String newDbServer) = [url, dbServer]

 

        if ( (dbServer != null) && (dbServer.contains('${X_ENGINE_SERVER}')) ) {

            newDbServer = System.getenv("X_ENGINE_SERVER")

        }

        if ( (url != null) && (url.contains('${X_JBOSS}')) ) {

            newUrl = 'https://' + System.getenv("X_JBOSS") + '/x'

        }

        return {

            stringParam 'Browser', browser, 'parameter for browser driver';

            stringParam 'suiteXmlFile', xml, 'test suite name';

            stringParam 'URL', newUrl, 'GUI URL';

            stringParam 'DB_SERVER', newDbServer, 'DB Server or X ENGINE Server for tests';

        }

    }


and invoked it with:


parameters sxCtx.njGuiParam('firefox', 'xCI-tests', 'https://' + '${X_JBOSS}' + '/x', '${X_ENGINE_SERVER}');


but we got text "null" for both

On Thursday, September 7, 2017 at 12:52:09 PM UTC-4, TJC wrote:
Reply all
Reply to author
Forward
0 new messages