Files
devops-lib-gcp/docs/wiki/pages/build/scm-variable-scope.md
T
2026-08-26 02:02:24 +05:30

55 lines
1.9 KiB
Markdown

<!-- m-wiki: type=concept slug=scm-variable-scope topic=build base-sha=28f54cf7bef9 generated-at=2026-05-12T00:00:00+00:00 sources=[] -->
> Generated 2026-05-12 at base-sha 28f54cf7bef9. Type: concept. 0 sources.
# SCM Variable Scope
The `scm` variable is only available inside consumer Jenkinsfiles, not inside `vars/` or `src/` of the shared library. Referencing it in library code causes a runtime `MissingPropertyException`.
## Where it applies in this repo
`vars/eksCICD.groovy` and all files under `src/com/meesho/`
## Why `scm` is unavailable
The `scm` variable (branch, remote URL, credentials) is injected by the GitHub Branch Source plugin into **consumer Jenkinsfiles** at the time they are loaded by Jenkins. Library code (everything under `vars/` and `src/`) is a separate classloader context — the plugin does not inject `scm` there.
Attempting to access `scm.branches` or `scm.userRemoteConfigs` from library code will throw:
```
MissingPropertyException: No such property: scm for class: groovy.lang.Binding
```
## Correct alternatives
Inside library code, use the Jenkins-injected environment variables instead:
| Need | Use instead of `scm.*` |
|------|------------------------|
| Branch name | `env.BRANCH_NAME` |
| Repository URL | `env.GIT_URL` |
| PR number | `env.CHANGE_ID` |
| PR source branch | `env.CHANGE_BRANCH` |
| PR target branch | `env.CHANGE_TARGET` |
All of these are set by the GitHub Branch Source plugin before library code runs.
## Related
- [Entry points](../02-ENTRYPOINTS.md) — where this constraint applies
- [Environment mapping](../05-ENVIRONMENT-MAPPING.md) — `env.CHANGE_ID` is the PR-build detector
## Sources
(no raw/ sources)
## Notes
<!-- Anything below is human-owned. wiki-init never reads or modifies content under this heading. -->
---
[← Wiki index](../../index.md)
<!-- atomic: keep this page ≤600 words. New scope → new concept page that builds on this one. Do not append paragraphs here. -->