How to pass params from Ansible to Jenkins Job triggered by Ansible Playbook?

34 views
Skip to first unread message

Mimo

unread,
May 7, 2020, 3:53:50 PM5/7/20
to Ansible Project

Hello everyone,

I checked Ansible documentation, I did not find answers there or anywhere of how I can pass params to the Jenkins Job,so these params should be as an input params to this Jenkins Job and they will be used in that Job, So is there a way to make this happen?

Thank you already for your answers

David Foley

unread,
May 7, 2020, 4:02:20 PM5/7/20
to Ansible Project
Hi,

In order to push jobs from Ansible or even Python to Jenkins you need to make sure Remote Trigger is enable and an API Token has been created for your Jenkins User. You can Then just use a Post request using the Ansible URI module

Mimo

unread,
May 7, 2020, 4:33:53 PM5/7/20
to ansible...@googlegroups.com
can you explain in more details please? it is not clear to me

On Thu, May 7, 2020 at 10:02 PM David Foley <david...@mycit.ie> wrote:
Hi,

In order to push jobs from Ansible or even Python to Jenkins you need to make sure Remote Trigger is enable and an API Token has been created for your Jenkins User. You can Then just use a Post request using the Ansible URI module

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/81063e55-65f0-487d-9953-03a2cd19b00c%40googlegroups.com.
Message has been deleted
Message has been deleted

Mimo

unread,
May 7, 2020, 4:44:26 PM5/7/20
to Ansible Project
it is not clear how to make the params as input there, it is easy to make it through Jenkins pipelines, but I am using Ansible, so I am expecting to have a Jenkins module that will build a job in Jenkins (or in my case handle the params to already existing job in Jenkins

David Foley

unread,
May 7, 2020, 5:08:12 PM5/7/20
to Ansible Project
Using the Example Curl -X you can use the Ansible URI Module curl -X POST http://developer:developer@localhost:8080/job/test/buildWithParameter --data-urlencode json='{"parameter": [{"name":"paramA", "value":"123"}]}'---
  - name: Jenkins Remote Build 
    hosts: localhost
    connection: local
    tasks:
    - name: Adding Virtual Machine to Blackout
      uri:
        url: http://developer:developer@localhost:8080/job/test/buildWithParameter
        method: POST
        body_format: JSON
        body:
        "{\"parameter\":             [{\"name\":\"Test\"},             {\"vaule\":\"123\"}]}        status_code: 200


Reply all
Reply to author
Forward
0 new messages