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

Build variables are not available during the ansible-playbook execution

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      It would be nice to inject the build variables into the ansible-playbook execution. It should probably be an optional feature.

        Attachments

          Activity

          Hide
          sirot Jean-Christophe Sirot added a comment -

          fixed in version 0.5

          Show
          sirot Jean-Christophe Sirot added a comment - fixed in version 0.5
          Hide
          piotrminkowski Piotr Minkowski added a comment - - edited

          I tried to use jenkins BUILD_ID environment variable in my jenkins pipeline. It does not work.

          Logs:
          TASK [copy file] ***************************************************************
          fatal: [10.10.99.56]: FAILED! =>

          {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'BUILD_ID' is undefined"}

          

          Pipeline:

          stage('deploy') {
              node {
                  print env.BUILD_ID
                  ansiblePlaybook playbook: 'start/src/main/resources/ansible.yml', colorized: true
              }
          }
          

          Ansible playbook:

          ---
          - hosts: bsa
            remote_user: bsa
            tasks:
            - name: copy file
              template: src=settings.j2 dest=/opt/bsa/start/settings.yml
          

          settings.j2 file:

          - build_id: {{BUILD_ID}}
          
          Show
          piotrminkowski Piotr Minkowski added a comment - - edited I tried to use jenkins BUILD_ID environment variable in my jenkins pipeline. It does not work. Logs: TASK [copy file] *************************************************************** fatal: [10.10.99.56] : FAILED! => {"changed": false, "failed": true, "msg": "AnsibleUndefinedVariable: 'BUILD_ID' is undefined"}  Pipeline: stage( 'deploy' ) { node { print env.BUILD_ID ansiblePlaybook playbook: 'start/src/main/resources/ansible.yml' , colorized: true } } Ansible playbook: --- - hosts: bsa remote_user: bsa tasks: - name: copy file template: src=settings.j2 dest=/opt/bsa/start/settings.yml settings.j2 file: - build_id: {{BUILD_ID}}
          Hide
          szhekpis Sergey Zhekpisov added a comment - - edited

          Tried to use versioning with Ansible plugin, does not work both for fields "Extra variables" and for "Additional variables"

          [Deploy_webadmin2] $ ansible-playbook deploy.yml -i hosts -l dev2 -f 5 --extra-vars VERSION=${WEBADMIN2_VERSION}

          Show
          szhekpis Sergey Zhekpisov added a comment - - edited Tried to use versioning with Ansible plugin, does not work both for fields "Extra variables" and for "Additional variables" [Deploy_webadmin2] $ ansible-playbook deploy.yml -i hosts -l dev2 -f 5 --extra-vars VERSION=${WEBADMIN2_VERSION}
          Hide
          sirot Jean-Christophe Sirot added a comment -

          Piotr Minkowski Variables are injected in the process environment. It means you have to use this syntax to use in your template settings.j2:

          - build_id: {{ lookup('env','BUILD_ID') }}
          
          Show
          sirot Jean-Christophe Sirot added a comment - Piotr Minkowski Variables are injected in the process environment. It means you have to use this syntax to use in your template settings.j2: - build_id: {{ lookup('env','BUILD_ID') }}
          Hide
          sirot Jean-Christophe Sirot added a comment -

          Sergey Zhekpisov Can you give me more details on your the failing job configuration

          Show
          sirot Jean-Christophe Sirot added a comment - Sergey Zhekpisov Can you give me more details on your the failing job configuration

            People

            • Assignee:
              sirot Jean-Christophe Sirot
              Reporter:
              sirot Jean-Christophe Sirot
            • Votes:
              6 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: