-
Bug
-
Resolution: Unresolved
-
Major
When a job is started & trying to checkout an unavailable commitId on a valid repository, then the GIT_COMMIT environment variable is still set but to the last fetched commit value.
As side effect, all post job steps or plugin working later will get a wrong value from the GIT_COMMIT & act on that wrong commit (github status events, etc...).
When a scm checkout fails & stop the build, the GIT_COMMIT value should not be set.
How to reproduce
scenario 1 in one step( see One step config.xml attached file)
This one will fail even on a clean/new workspace if nothing was initially fetched or if everything was wiped out
- just run "build with parameters" & set "unvalid treeish value" as TREEISH value
Started by user unknown or anonymous
Rebuilds build #12
Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building in workspace c:\w\test wrong commit_id
No credentials specified
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository https://github.com/github/gitignore
> git.exe init c:\w\test wrong commit_id # timeout=10
Fetching upstream changes from https://github.com/github/gitignore
> git.exe --version # timeout=10
> git.exe fetch --tags --progress https://github.com/github/gitignore +refs/heads/:refs/remotes/origin/ # timeout=180
> git.exe config remote.origin.url https://github.com/github/gitignore # timeout=10
> git.exe config --add remote.origin.fetch +refs/heads/:refs/remotes/origin/ # timeout=10
> git.exe config remote.origin.url https://github.com/github/gitignore # timeout=10
Fetching upstream changes from https://github.com/github/gitignore
> git.exe fetch --tags --progress https://github.com/github/gitignore +refs/heads/:refs/remotes/origin/ # timeout=180
> git.exe rev-parse "origin/unvalid treeish value^
Unknown macro: {commit}
" # timeout=10
> git.exe rev-parse "unvalid treeish value^" # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
GIT COMMIT is: 21e9f06539cdbc1ccbbb2ce59cd667be3e172fc8
Finished: FAILURE
GIT_COMMIT is set anyway to 21e9f06539cdbc1ccbbb2ce59cd667be3e172fc8 ! shouldn't be set !
scenario 2, restarting a build by setting a wrong TREEISH the second time (attached sample config 1.xml file)
- Run the job a first time on master to initialize the workspace
Started by an SCM change
Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building in workspace c:\w\test wrong commit_id
No credentials specified
> git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url https://github.com/github/gitignore # timeout=10
Fetching upstream changes from https://github.com/github/gitignore
> git.exe --version # timeout=10
> git.exe fetch --tags --progress https://github.com/github/gitignore +refs/heads/:refs/remotes/origin/ # timeout=10
> git.exe rev-parse "origin/master^
Unknown macro: {commit}
" # timeout=10
Checking out Revision 21e9f06539cdbc1ccbbb2ce59cd667be3e172fc8 (origin/master)
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f 21e9f06539cdbc1ccbbb2ce59cd667be3e172fc8 # timeout=10
Commit message: "Added jarRepositories.xml as an optional ignore (#3254)"
First time build. Skipping changelog.
GIT COMMIT is: 21e9f06539cdbc1ccbbb2ce59cd667be3e172fc8
Finished: SUCCESS - Run a second time with a bad treeish value "unvalid treeish value"
Started by user unknown or anonymous
Rebuilds build #8
Running as SYSTEM
[EnvInject] - Loading node environment variables.
Building in workspace c:\w\test wrong commit_id
No credentials specified
> git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url https://github.com/github/gitignore # timeout=10
Fetching upstream changes from https://github.com/github/gitignore
> git.exe --version # timeout=10
> git.exe fetch --tags --progress https://github.com/github/gitignore +refs/heads/:refs/remotes/origin/ # timeout=10
> git.exe rev-parse "origin/unvalid treeish value^
Unknown macro: {commit}
" # timeout=10
> git.exe rev-parse "unvalid treeish value^" # timeout=10
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
GIT COMMIT is: 21e9f06539cdbc1ccbbb2ce59cd667be3e172fc8
Finished: FAILUREThe GIT_COMMIT env var is set anyway to the previous active fetched versoin of the previous build ! instead of not being set as the checkout out failed.
Extra info
Groovy Post build step to display the GIT_COMMIT env value:
def v = manager.envVars.get("GIT_COMMIT") manager.listener.logger.println("GIT COMMIT is: "+v)
Thx in advance,
Best regards
Post build jobs will need to work around the issue by detecting the failure of the predecessor job.