# Testing Jenkins Job DSL

**URL:** <https://community.jenkins.io/t/testing-jenkins-job-dsl/13149>\
**Category:** Using Jenkins\
**Tags:** question\
**Created:** [March 8, 2024, 1:24pm UTC](https://community.jenkins.io/t/testing-jenkins-job-dsl/13149 "2024-03-08T13:24:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![72nat](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/72nat/32/7339_2.png) [@72nat](https://community.jenkins.io/u/72nat)\
**Post date:** [March 8, 2024, 1:24pm UTC](https://community.jenkins.io/t/testing-jenkins-job-dsl/13149/1 "2024-03-08T13:24:08Z")

</div>

Hi All  
I’m currently testing my DSL scripts using gradle based on this example.

> **[Testing DSL Scripts](https://github.com/jenkinsci/job-dsl-plugin/wiki/Testing-DSL-Scripts)**
>
> A Groovy DSL for Jenkins Jobs - Sweeeeet! Contribute to jenkinsci/job-dsl-plugin development by creating an account on GitHub.

With the following details:  
Gradle Version: **5.3.1**  
Job DSL Version: **1.70**  
Jenkins Version: **2.138.2**

But having below error:

```auto
JobScriptsSpec > test script param_job.groovy STANDARD_OUT
    Processing provided DSL script

JobScriptsSpec > test script param_job.groovy FAILED
    Expected no exception to be thrown, but got 'javaposse.jobdsl.dsl.DslScriptException'
        at spock.lang.Specification.noExceptionThrown(Specification.java:118)
        at JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:26)

        Caused by:
        javaposse.jobdsl.dsl.DslScriptException: (script, line 15) No such property: JENKINS_INSTANCE_NAME for class: javaposse.jobdsl.dsl.jobs.WorkflowJob
            at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:114)
            at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts_closure1(AbstractDslScriptLoader.groovy:61)
            at groovy.lang.Closure.call(Closure.java:411)
            at groovy.lang.Closure.call(Closure.java:427)
            at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScripts(AbstractDslScriptLoader.groovy:46)
            at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:87)
            at JobScriptsSpec.test script #file.name(JobScriptsSpec.groovy:23)

            Caused by:
            groovy.lang.MissingPropertyException: No such property: JENKINS_INSTANCE_NAME for class: javaposse.jobdsl.dsl.jobs.WorkflowJob
                at script.run_closure1(script:15)
                at groovy.lang.Closure.call(Closure.java:411)
                at groovy.lang.Closure.call(Closure.java:427)
                at javaposse.jobdsl.dsl.JobParent.processItem(JobParent.groovy:239)
                at javaposse.jobdsl.dsl.JobParent.pipelineJob(JobParent.groovy:87)
                at script.run(script:1)
                at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScript(AbstractDslScriptLoader.groovy:138)
                at javaposse.jobdsl.dsl.AbstractDslScriptLoader.runScriptEngine(AbstractDslScriptLoader.groovy:108)
                ... 6 more

```

When testing below script:

```auto
pipelineJob('param-job') {
    description('This job is parameterized')
    parameters {
        stringParam('DevelopBranch', 'develop', 'The develop branch from development.')
        stringParam('RepoName', 'test_repo', 'The name of the repository')
        stringParam('NewParam', 'param1', 'The name of the parameter')
    }

    if (JENKINS_INSTANCE_NAME == 'test') {
        triggers {
            cron('H 6 * * *')
        }
    }

    logRotator {
        numToKeep(10)
        daysToKeep(7)
    }
    // definition {
    // cps {
    // script(readFileFromWorkspace('./vars/param.groovy'))
    // }

    // }
}

```

By the way **JENKINS\_INSTANCE\_NAME** is define in the global variables.

Can anyone help me fix this error?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![uhafner](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/uhafner/32/68_2.png) [@uhafner](https://community.jenkins.io/u/uhafner)\
**Post date:** [March 8, 2024, 1:29pm UTC](https://community.jenkins.io/t/testing-jenkins-job-dsl/13149/2 "2024-03-08T13:29:36Z")

</div>

Are you still running Jenkins 2.138.2? This release is 6 years old and not supported anymore.

---

<div class="post-metadata">

**Author:** ![72nat](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/72nat/32/7339_2.png) [@72nat](https://community.jenkins.io/u/72nat)\
**Post date:** [March 8, 2024, 1:32pm UTC](https://community.jenkins.io/t/testing-jenkins-job-dsl/13149/3 "2024-03-08T13:32:12Z")

</div>

Yes, unfortunately it is the current version the project is using.

But to note, I also tried running it on local jenkins with version 2.447 and yet the same error.

---

<div class="post-metadata">

**Author:** ![72nat](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/72nat/32/7339_2.png) [@72nat](https://community.jenkins.io/u/72nat)\
**Post date:** [March 8, 2024, 1:35pm UTC](https://community.jenkins.io/t/testing-jenkins-job-dsl/13149/4 "2024-03-08T13:35:33Z")

</div>

I know that based on this document there is no property  
like **JENKINS\_INSTANCE\_NAME**.  
[https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob](https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob)

But this is defined as Global variables.  
Is there a workaround on this just to make the testing successful?  
Thanks

---

<div class="post-metadata">

**Author:** ![uhafner](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/uhafner/32/68_2.png) [@uhafner](https://community.jenkins.io/u/uhafner)\
**Post date:** [March 8, 2024, 2:27pm UTC](https://community.jenkins.io/t/testing-jenkins-job-dsl/13149/5 "2024-03-08T14:27:52Z")

</div>

I don’t think that you can use environment variables in such a way, but I never used them so I do not have a better solution.
