1

I've got a Jenkins pipeline that builds docker images and tags them with the git hash. I also have another parameterized Jenkins pipeline that takes in a couple of string/choice parameters for deployment of the docker images. I'd love for the build pipeline to append some strings to the choice parameters in the deployment pipeline, so that when a user runs the deployment pipeline, he/she is just presented with a list of recently successfully built docker images to choose from.

Anyone know how to do this?

Victor Trac
  • 391
  • 1
  • 4
  • 13

1 Answers1

1

One way would be for your first job to set an environment variable with the list of recent built image tabs (one per line).
See declarative pipeline environment directive.

Then, following "Dynamic Parameter in Jenkinsfile?", you can use an external function like:

#!/bin/groovy

def envs = loadEnvs();

properties([
   parameters([
      choice(choices: envs, description: 'Please select an image tag', name: 'Env')
   ])
])

That should be enough to build a choice parameter list.

"Pipeline: How to manage user inputs " (May 10th, 2017, two weeks ago) shows an alternative command, but not valid in the Declarative Pipeline syntax:

You have to use the input step to achieve it.
It will give you something like this :

stage 'promotion'
def userInput = input(
 id: 'userInput', message: 'Let\'s promote?', parameters: [
 [$class: 'TextParameterDefinition', defaultValue: 'uat', description: 'Environment', name: 'env'],
 [$class: 'TextParameterDefinition', defaultValue: 'uat1', description: 'Target', name: 'target']
])
echo ("Env: "+userInput['env'])
echo ("Target: "+userInput['target'])
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Are you sure that the last part is for the declarative pipelines? This feels a lot like scripted pipeline to me. AFAIK you can't set variables in declarative, and the `stage` syntax looks like the already deprecated one from scripted pipelines. IMHO the only way to use `input` in a declarative pipeline is to externalize the `input` into a function which is then called as a normal (blocking) build step. – StephenKing May 23 '17 at 05:11
  • The difference between `parameters` and `input` is that the first asks for feedback before the build starts, while the latter one can be used at any time _during_ the build. – StephenKing May 23 '17 at 05:21
  • @StephenKing You are correct. I have amended the answer to make that clearer: there does not seem to be a direct DSL native solution. – VonC May 23 '17 at 05:58