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

Declarative Pipeline: Allow env vars to be used in options block

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • pipeline
    • None

      I'm trying to use the lock() option in an options block of a stage. I want the lock resource to be dynamic (depending on an environment variable).

      For example:

          environment  {
              BRANCH_TO_USE = get_branch_to_use()
          }
      stages {
          stage('Lock build'){
              options {
                lock(resource: "lock-${env.BRANCH_TO_USE}", quantity: 1)
              }
              stages {
      ...
      

      But the resulting string is always "lock-null". I tried it without "env." but to no avail.

      I would expect this to work especially since the environment variable is available in the coming stages with no problem.

      Is there a way to support this or a possible workaround?

            Unassigned Unassigned
            mariusmeyer Marius Meyer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: