0

Parameterized Build steps in a Jenkinsfile to run Ansible Playbooks?

How do i add Parameterized Build steps in a Jenkinsfile to run Ansible Playbooks?

Thanks :)

3 comments

  • 0
    Avatar
    Allan Burdajewicz

    Hi Hela,

    Is your requirement to trigger a parameterized build from a Jenkinsfile ? This is possible using the build like for example:

    build job: 'myFolder/myParameterizedJob', parameters: [string(name: 'testParam', value: 'valueForThisParameter')]

    This will trigger the job myFolder/myParameterizedJob and pass the value valueForThisParameter for the parameter testParam.

    Or is your requirement to parameterize a Job from the Jenkinsfile ? In that case, you need to use the properties step like for example:

    properties([parameters([string(defaultValue: 'myDefaultValue', description: '', name: 'myParam')])])

    You then need to build the pipeline once so that properties are loaded. The job will be parameterized.

    Regards,

  • 0
    Avatar
    Hela Drira

    Hi Allan,

    i wrote this :

    • node {
    • stage ('Basic install') {
    • deleteDir()
    • checkout scm
    • sh 'ls -lR;'
    • wrap([$class: 'AnsiColorBuildWrapper', colorMapName: "xterm"]) {
    • ansiblePlaybook(
    • playbook: 'ansible/base-install.yml',

    but instead of giving directly the playbook Name in th jenkinsfile

    I want to get a response if it is possible asking me what playbook do i wanna run?

    Regards

  • 0
    Avatar
    Denys Digtiar

    The second option that Allan described (i.e. Pipeline project parameters or `properties` step in case of Multi-branch), allows you to ask for the playbook up front before launching the build.

    If you want to pause in the middle to ask you can try using the Pipeline Input Step. However, keep in mind that you have to do the input step outside the node step otherwise the executor will be blocked, ref https://www.cloudbees.com/blog/top-10-best-practices-jenkins-pipeline-plugin

Please sign in to leave a comment.