# JobDSL / git scm checkout does not cope correctly with env-vars

**URL:** <https://community.jenkins.io/t/jobdsl-git-scm-checkout-does-not-cope-correctly-with-env-vars/35679>\
**Category:** Using Jenkins\
**Created:** [October 3, 2025, 9:13am UTC](https://community.jenkins.io/t/jobdsl-git-scm-checkout-does-not-cope-correctly-with-env-vars/35679 "2025-10-03T09:13:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![con-f-use](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/con-f-use/32/7777_2.png) [@con-f-use](https://community.jenkins.io/u/con-f-use)\
**Post date:** [October 3, 2025, 9:13am UTC](https://community.jenkins.io/t/jobdsl-git-scm-checkout-does-not-cope-correctly-with-env-vars/35679/1 "2025-10-03T09:13:29Z")

</div>

I have [Job DSL](https://plugins.jenkins.io/job-dsl/) definition:

```auto
pipelineJob("qanix-webhook-nodes") {
    parameters {
        stringParam('SCM_PROJECT', '', 'the project on git-server')
        stringParam('SCM_REPO', '', 'the repo-name on git-server')
        stringParam('SCM_BRANCH', '', 'the branch on git-server')
        stringParam('SCM_COMMIT', '', 'The commit to run the build for')
        stringParam('SCM_SHORT_COMMIT', '', 'First few characters of SCM_COMMIT above')
    }

    definition {
        cpsScm {
            scm {
                git {
                    remote {
                        url("ssh://git@some-git-server.org:1234/project/reponame.git")
                        credentials("git-ssh")
                    }
                    branch('${SCM_COMMIT}');
                }
                scriptPath(".jenkins-ci/some-pipeline.groovy")
            }
        }
    }
}

```

Documentation clear on how `${SCM_COMMIT}` is supposed to work:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/3X/2/1/2143688a54367b75f42b6860c59297b4c61f7f4f.png)

Yet when I run this, **jenkins fails to checkout the commit by hash** (see picture), even though it got the correct hash and the corresponding commit is on the remote git server.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/3X/e/0/e00e2825519fe4907a40e08588a5333e033ffa3c.png)

If I switch out `${SCM_COMMIT}` for `${SCM_BRANCH}`, it works, but that is error prone, because for instance it checks out the old HEAD if there was a force-push and has other such issues.

---

<div class="post-metadata">

**Author:** ![Artalus](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/artalus/32/11413_2.png) [@Artalus](https://community.jenkins.io/u/Artalus)\
**Post date:** [October 3, 2025, 9:53am UTC](https://community.jenkins.io/t/jobdsl-git-scm-checkout-does-not-cope-correctly-with-env-vars/35679/2 "2025-10-03T09:53:43Z")

</div>

I presume this is because you use `branch()` directive in your DSL.

Even if in your `SCM_COMMIT` variable/parameter you pass just the commit, `42…0e` without anything before it, Jenkins still mistakes it for a branch name, and attemtps to use the `refs/heads/`syntax with it. This causes git to lookup the `42…0e`_branch_, which does not exist, and so it fails.

I don’t have a Jenkins instance at hand and might be mistaking this for some other part of DSL, but consult with your `http://jenkins.url/plugin/job-dsl/api-viewer/index.html` reference. I think in addition to the handy [`git{}`shorthand](https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-definition-cpsScm-scm-git) there should be also something like `gitSCM` with `Dynamic` label – extremely verbose but more configurable, allowing you to use other directives than just `branch()`. Refer to `http://jenkins.url/plugin/job-dsl/api-viewer/index.html#path/job-scm-gitSCM` on your controller.

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [October 3, 2025, 12:40pm UTC](https://community.jenkins.io/t/jobdsl-git-scm-checkout-does-not-cope-correctly-with-env-vars/35679/3 "2025-10-03T12:40:49Z")

</div>

> [@con-f-use](#):
>
> ```auto
> scm {
> git {
> remote {
> url("ssh://git@some-git-server.org:1234/project/reponame.git")
> credentials("git-ssh")
> }
> branch('${SCM_COMMIT}');
> }
> scriptPath(".jenkins-ci/some-pipeline.groovy")
> }
> 
> ```

> [@con-f-use](#):
>
> Yet when I run this, **jenkins fails to checkout the commit by hash**

If that code results in a Pipeline that has the `git` Pipeline step, then you’re facing a documented limitation of the `git` Pipeline step. The `git` step only supports checkout of branches. The [documentation](https://www.jenkins.io/doc/pipeline/steps/git/#git-git) of the `git` step says:

> the `git` step does **not** support:
> 
> - SHA-1 checkout
> - Tag checkout
> - Submodule checkout
> - Sparse checkout
> - Large file checkout (LFS)
> - Reference repositories
> - Branch merges
> - Repository tagging
> - Custom refspecs
> - Timeout configuration
> - Changelog calculation against a non-default reference
> - Stale branch pruning

The `checkout` step supports all those checkout forms. Examples are included in the [git plugin documentation](https://plugins.jenkins.io/git/#plugin-content-checkout-with-defaults)
