Search code examples
apipostmanrundeck

Run a job via the rundeck API with parameters in postman


I am trying around with the Rundeck API. I was able to get a simple Job running. But now I am trying to run a job, that has a job option. The job option for this job is an IP, so Rundeck starts the Job only on this machine. When I use the API, I don't know how to set the parameter. I am using the tool Postman, where I only receive the message "Job options were not valid: Option 'IP' is required".

I looked it up on the rundeck documentation and I found this for postman

In the rundeck documentation is this example:

argString: argument string to pass to the job, of the form: -opt value -opt2 value ....

How can I use it for my IP?


Solution

  • Using this Rundeck Job Definition:

    - defaultTab: nodes
      description: ''
      executionEnabled: true
      id: 9f04657a-eaab-4e79-a5f3-00d3053f6cb0
      loglevel: INFO
      name: HelloWorld
      nodeFilterEditable: false
      options:
      - name: opt1
      plugins:
        ExecutionLifecycle: null
      scheduleEnabled: true
      sequence:
        commands:
        - exec: echo "hello ${option.opt1}"
        keepgoing: false
        strategy: node-first
      uuid: 9f04657a-eaab-4e79-a5f3-00d3053f6cb0
    

    And based on this, you can do it by putting the options in JSON format (json body) on Postman:

    {
        "options": {
            "opt1":"world"
        }
    }
    

    This is the code snipped in cURL format:

    curl --location --request POST 'pop-os:4440/api/38/job/9f04657a-eaab-4e79-a5f3-00d3053f6cb0/run' \
    --header 'X-Rundeck-Auth-Token: GuaoD6PtH5BhobhE3bAPo4mGyfByjNya' \
    --header 'Content-Type: application/json' \
    --header 'Cookie: JSESSIONID=node01tz8yvp4gjkly8kpj18h8u5x42.node0' \
    --data-raw '{
        "options": {
            "opt1":"world"
        }
    }'
    

    Check how looks on Postman.