Rundeck REST端点,用于获取作业和节点等项目详细信息

时间:2017-03-15 13:19:41

标签: rundeck

我正在使用rundeck 1.6版本,只想检查是否有任何1.6或任何最新版本的REST端点解决了我的以下要求。 如果我传递一个项目名称,它会为我提供在该项目下创建的所有作业,以及它们被配置为运行的节点名称。

由于 -SAM

1 个答案:

答案 0 :(得分:1)

以下代码使用Tokens authentication。您也可以使用Password Authentication

jitter

输出:

#!/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