RjOllos
RjOllos

Reputation: 2934

Determine Git revision in Jenkins without checkout

Using Jenkin multibranch declarative pipeline with Git. In the stage, the necessary environment variable exists: GIT_COMMIT. However, I don't need a checkout in this stage for the steps, I just need GIT_COMMIT to construct a blob path to add some lock files in Azure. I would like to avoid the checkout.

When I add the option:

Options { skipDefaultCheckout() }

now, the environment variable GIT_COMMIT doesn't exist in the stage. Is there any way to get just the GIT_COMMIT without performing a checkout?

The BRANCH_NAME is in the environment, so I could check the HEAD revision of the branch but that wouldn't be correct if there was another commit before the stage executed. The Git plugin knows how to checkout the correct revision but I can't see any environment variables output by printenv that provide the revision.

Upvotes: 0

Views: 47

Answers (0)

Related Questions