Home Add gitparameter in jenkins pipeline
Reply: 1

Add gitparameter in jenkins pipeline

Arati Kulkarni
1#
Arati Kulkarni Published in 2017-12-05 13:37:28Z

I need the userInput when executing the pipeline. The input will be the git branch of a particular repository. As we can configure gitparameter in the jenkins job how do we configure it in the jenkins pipeline. I have got the pipeline code as follows >

   stage 'promotion'
   def userInput = input(
   id: 'userInput', message: 'Let\'s promote?', parameters: [
   [$class: 'GitParameterDefinition', description: 'Environment', name: 'env',type: 'Branch'],
   [$class: 'TextParameterDefinition', defaultValue: 'uat1', description: 'Target', name: 'target']
])
  echo ("Env: "+userInput['env'])
  echo ("Target: "+userInput['target'])

All I get is an empty input box how do I configure it with the git repository in the pipeline itself.

TrafLaw
2#
TrafLaw Reply to 2017-12-07 05:23:00Z

You can do it as follow:

node { 
stage ('input') { 

   def userInput = input message: 'enter git details',
     parameters: [
     string(defaultValue: 'dev', description: 'branch name', name: 'branch'),
     string(defaultValue: '', description: 'repo url', name: 'url')
     ]

    git branch: userInput['branch'], credentialsId: 'creds', url: userInput['url']
   }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303561 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO