jenkinsci / jenkinsci/workflow-cps-plugin
[JENKINS-66345] Global variable in shared-library is missing after jenkins restart
- Dominant language
- Java
- Stars
- 186
- Forks
- 213
- Avg merge
- 12h 12m
- Merged PRs (30d)
- 8
Description
I have defined global variable as doc: https://www.jenkins.io/doc/book/pipeline/shared-libraries/#defining-global-variables
@groovy.transform.Field
def yourField = [:]
This is the problem: Jenkins is restarted when one pipeline build is running, after jenkins is back, the global variable defined in vars/test.groovy because empty.
The following is the logs of pipeline build:
16:12:28 {~~~~~~ globalReference defined in pipeline:={PRD_MODE=, job_start_time=1628583133894}}
[Pipeline] echo*16:12:28* ~~~~~~~~~[test] defined in vars: foo
[Pipeline] echo*16:12:28* ~~~!!!!! lib object:org.jenkinsci.plugins.workflow.libs.LibraryStep$LoadedClasses@116dced
[Pipeline] sleep*16:12:28* Sleeping for 1 min 40 sec
Resuming build at Tue Aug 10 08:14:27 UTC 2021 after Jenkins restart
Waiting to resume part of PR » agents » PR_agent_1 #4 | PR_Sanity_33422_zhul13_1626940307645_0_T_0:
Finished waiting
Ready to run at Tue Aug 10 08:15:14 UTC 2021*16:15:14* No need to sleep any longer
[Pipeline] echo*16:15:14* ~~!!!!! after sleep lib object :org.jenkinsci.plugins.workflow.libs.LibraryStep$LoadedClasses@232cdd2e
[Pipeline] echo*16:15:15* sleep back [test]defined in vars : null
[Pipeline] echo*16:15:15* {~~~~~ globalReference defined in pipeline:={PRD_MODE=, job_start_time=1628583133894}}
The value in vars is missing, but the globalReference defined in pipeline is ok.
---
Originally reported by leo_zhu, imported from: Global variable in shared-library is missing after jenkins restart
Raw content of original issue
I have defined global variable as doc: https://www.jenkins.io/doc/book/pipeline/shared-libraries/#defining-global-variables
@groovy.transform.Field
def yourField = [:]This is the problem: Jenkins is restarted when one pipeline build is running, after jenkins is back, the global variable defined in vars/test.groovy because empty.
The following is the logs of pipeline build:
16:12:28 {~~~~~~ globalReference defined in pipeline:={PRD_MODE=, job_start_time=1628583133894}}
[Pipeline] echo*16:12:28* ~~~~~~~~~[test] defined in vars: foo
[Pipeline] echo*16:12:28* ~~~!!!!! lib object:org.jenkinsci.plugins.workflow.libs.LibraryStep$LoadedClasses@116dced
[Pipeline] sleep*16:12:28* Sleeping for 1 min 40 sec
Resuming build at Tue Aug 10 08:14:27 UTC 2021 after Jenkins restart
Waiting to resume part of PR » agents » PR_agent_1 #4 | PR_Sanity_33422_zhul13_1626940307645_0_T_0:
Finished waiting
Ready to run at Tue Aug 10 08:15:14 UTC 2021*16:15:14* No need to sleep any longer
[Pipeline] echo*16:15:14* ~~!!!!! after sleep lib object :org.jenkinsci.plugins.workflow.libs.LibraryStep$LoadedClasses@232cdd2e
[Pipeline] echo*16:15:15* sleep back [test]defined in vars : null
[Pipeline] echo*16:15:15* {~~~~~ globalReference defined in pipeline:={PRD_MODE=, job_start_time=1628583133894}}The value in vars is missing, but the globalReference defined in pipeline is ok.
environment
```
jenkins 2.263.4
Pipeline: Groovy 2.91
```
Contributor guide
Research direction
Start with the shared-library example in vars/test.groovy and reproduce the pipeline using the reported Jenkins 2.263.4 and Pipeline: Groovy 2.91 environment. Compare the global variable before and after a Jenkins restart, using the log sequence as the expected failure case. Done means the variable retains its value after resumption, with a regression test covering the restart scenario.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- ci-cd
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100