Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-62250

Provide the GIT_COMMIT variable without the need to checkout SCM

    Details

    • Similar Issues:

      Description

      This value should be known before the SCM is checked out, either from repository scanning, or from the webhook.

      It is pretty normal to want to define environment variables globally in the pipeline. Those variables may depends on GIT_COMMIT. However, for GIT_COMMIT to be available, `agent none` cannot be used.

       

      The problem caused by inability to use `agent none` globally
      If there is an input step in the pipeline and a global agent is used, once the input step is reached, an executor will still be occupied. Eventually, once enough branches reach the input step, all executors will be busy.

      With global `agent none` it is possible not to consume an agent when waiting for the input if one follows some additional ceremony of adding `beforeAgent true` to `when` in stages with input steps (and defining a fake always-true condition in `when` if there is no need for a `when` condition otherwise).

      However, when one needs GIT_COMMIT in multiple different steps, it forces every step that needs it to check out SCM (which otherwise would be possible to skip) to do so. It also forces stages that could otherwise execute with `agent none` to use an agent (e.g. stages with `input` and `build job` steps only). If also forces a huge amount of duplication of the same environment variable definitions depending on GIT_COMMIT.

       

      None of that would be necessary if GIT_COMMIT (and other SCM variables) were available without checking out SCM.

       

      Non-solutions

      1. Setting global global environment with a scripted procedure - I don't think this will work with stage restarts, and I'm too burned out to try that.
      2. Using a different set of plugins from what Blue Ocean gives.

      Current work-around
      Use agent none globally and copy environment variable definitions to every step. Replace every instance of `agent none` with `agent any`.

        Attachments

          Activity

          Hide
          karo Karoline Pauls added a comment - - edited

          This is actually even worse. It can lead to a deadlock.

          Let's assume there is a matrix build with 10 elements. The executor limit is 10. The matrix build needs to use a GIT_* variable in its Kubernetes agent pod template. That means that the matrix has to define `agent any` and the actual Kubernetes agent will be in matrix->stages->stage('...')->agent. This duplicates the number of executors taken. But if the number of matrix rows is equal to the number of available executors, the outer agents (which get allocated first) will take all executors before the inner agents which are responsible for completing the matrix can proceed.

          Show
          karo Karoline Pauls added a comment - - edited This is actually even worse. It can lead to a deadlock. Let's assume there is a matrix build with 10 elements. The executor limit is 10. The matrix build needs to use a GIT_* variable in its Kubernetes agent pod template. That means that the matrix has to define `agent any` and the actual Kubernetes agent will be in matrix->stages->stage('...')->agent. This duplicates the number of executors taken. But if the number of matrix rows is equal to the number of available executors, the outer agents (which get allocated first) will take all executors before the inner agents which are responsible for completing the matrix can proceed.

            People

            • Assignee:
              vaimr Denis Saponenko
              Reporter:
              karo Karoline Pauls
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: