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

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

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

can you explain in more details please? it is not clear to me

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

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