How to pass argumets to RunDeck Run API

SAJ picture SAJ · Dec 18, 2014 · Viewed 13.3k times · Source

I want to run a rundeck job using the run API. Would like to pass few parameters as well to the runDeck job during the run time.

Do I need to configure the job to accept parameters? How to pass parameters to run API?

Thanks in advance

Regards SJ

Answer

swapz83 picture swapz83 · Nov 16, 2016

Option 1: In absence of tokens, first login to get cookie

curl \
  -D - \
  -X POST \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -H "Cache-Control: no-cache" \
  -d "j_username=${RD_USER}&j_password=${RD_PASSWORD}" \
  --cookie-jar rd_cookie \
  "${RD_URL}/j_security_check"

Then, use the cookie received from successful login for subsequent transactions

curl \
  -D - \
  -X "POST" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d "{\"argString\":\"-arg1 val1 -arg2 val2 -arg3 val-3 -arg4 val4 \"}" \
  --cookie "@rd_cookie" \
  "${RD_URL}/api/16/job/${RD_JOB_ID}/executions"

Option 2: With a token, it's simpler

curl \
  -D - \
  -X "POST" -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-Rundeck-Auth-Token: ${RD_TOKEN}" \
  -d "{\"argString\":\"-arg1 val1 -arg2 val2 -arg3 val-3 -arg4 val4 \"}" \
  "${RD_URL}/api/16/job/${RD_JOB_ID}/executions"