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

Set default value for environment variable when not already set

      We'd like to set an environment variable for a pipeline job to inherit from a global environment variable when present, but to default to a reasonable value when not. This was possible in scripted pipeline using the following snippet:

       

      def foo = env.FOO ?: 'foo'
      withEnv(["BAR=${foo}"]) {
        // build
      }

      My attempts to recreate this in declarative pipelines have proven unsuccessful. If this is already possible, please provide some documentation. If it's not possible, please consider this a feature request.

       

          [JENKINS-45991] Set default value for environment variable when not already set

          Dave Hunt created issue -
          Andrew Bayer made changes -
          Labels New: declarative-variable-and-method-resolution
          Andrew Bayer made changes -
          Epic Link New: JENKINS-45422 [ 183590 ]
          Andrew Bayer made changes -
          Link New: This issue depends on JENKINS-42753 [ JENKINS-42753 ]
          Andrew Bayer made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          Liam Newman made changes -
          Status Original: Resolved [ 5 ] New: Closed [ 6 ]

            abayer Andrew Bayer
            davehunt Dave Hunt
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: