[JIRA] (JENKINS-60461) GIT_COMMIT shouldn't be set when scm cfailed

2 views
Skip to first unread message

louis@lecaroz.name (JIRA)

unread,
Dec 12, 2019, 7:40:04 AM12/12/19
to jenkinsc...@googlegroups.com
Louis Lecaroz created an issue
 
Jenkins / Bug JENKINS-60461
GIT_COMMIT shouldn't be set when scm cfailed
Issue Type: Bug Bug
Assignee: Mark Waite
Attachments: One step config.xml, sample config 1.xml
Components: git-plugin
Created: 2019-12-12 12:39
Labels: git plugins jenkins
Priority: Major Major
Reporter: Louis Lecaroz

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)

  1. 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

  2. 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: FAILURE

    The 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

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages