Sam
Sam

Reputation: 798

Rundeck REST endpoint for fetching project details like jobs and node

I am using rundeck 1.6 version and just want to check is there REST endpoint in any 1.6 or any latest version which solves my below requirement. If i pass a project name it gives me all the jobs created under that project with the node names on which they are being configured to run.

Thanks -Sam

Upvotes: 2

Views: 687

Answers (1)

Yang
Yang

Reputation: 888

There is, the following code uses Tokens authentication. You can also use Password Authentication

#!/bin/bash
RUNDECK_URL='localhost:4440' #<-----change it to your rundeck url
API_TOKEN='OyFXX1q4UzhTUe7deOUIPJKkrUnEwZlo' #<-----change it to your api koken
PROJECTS=`curl -H "Accept: application/json" http://$RUNDECK_URL/api/1/projects?authtoken=$API_TOKEN |tr "}" "\n"|tr "," "\n"|grep name|cut -d":" -f2 |tr -d "\""`

for proj in $PROJECTS; do
    #get all Jobs in all projects:
    echo "Project: $proj"
    PROJECT_OUTPUT=`curl -sS "http://$RUNDECK_URL/api/1/jobs?authtoken=$API_TOKEN&project=${proj}"`

    # get job definition and parse
    JOB_IDS=`echo $PROJECT_OUTPUT | grep -oP "(?<=<job id=')[^']+"`
    for id in $JOB_IDS; do
        echo $id #job id
        JOB_OUTPUT=`curl -sS "http://$RUNDECK_URL/api/1/job/$id?authtoken=$API_TOKEN"`
        echo $JOB_OUTPUT | grep -oP "(?<=<name>)[^<]+" #job name
        echo $JOB_OUTPUT | grep -oP "(?<=<filter>)[^<]+" #job node filter
    done
done

Output:

$ sh rundeck_test.sh 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    98    0    98    0     0   6292      0 --:--:-- --:--:-- --:--:--  6533
Project: TestProject
02a41aaa-eb50-4831-8762-80b798468cbe  <-------- job id
TestJob          <-------- job name, the job doesn't have node filter - running on rundeck
9b2ac9e9-0350-4494-a463-b43ba1e458ab
TestJob2
node1.exmple.com <-------- node filter value

Upvotes: 1

Related Questions