正在启动带有curl参数的rundeck作业

6ie5vjzr  于 2022-11-13  发布在  其他
关注(0)|答案(1)|浏览(196)

我想在提交后用gitlab-ci启动rundeck作业。所以我用curl命令调用rundeck作业。但有一个问题,我的作业中没有使用选项值,使用了默认值。但我的xml响应显示argString存在。
我使用的命令:

curl -X 'POST' -H 'Content-Type: application/json' -H 'X-Rundeck-Auth-Token: <my_token>' --data-urlencode 'argString=-LOCAL_REPO /home/rundeck/ -FILE_NAME archive_test.zip' 'https://<url:port>/api/1/job/<job_id>/run' -k

XML回应:

...
        <name>TEST_2args</name>
        <group></group>
        <project>Rundeck</project>
        <description>Job test </description>
        <options>
          <option name='LOCAL_REPO' value='/tmp/' />
          <option name='FILE_NAME' value='archive.zip' />
        </options>
      </job>
      <description>whoami ('Who am i ?') [... 3 steps]</description>
      <argstring>-LOCAL_REPO /home/rundeck/ -FILE_NAME archive_test.zip</argstring>
    </execution>
  </executions>

我不想使用默认值,但我在参数中传递的选项。
谢谢你的帮助

qc6wkl3g

qc6wkl3g1#

只是为了记录回答:您可以通过以下方式启动它(如果任何人需要,我都包含了节点过滤器):

#!/bin/sh

# protocol
protocol="http"
format="json"

# basic rundeck info
rdeck_host="yournode"
rdeck_port="4440"
rdeck_api="36"
rdeck_token="0jEkMXbPBUzx984HeM3RUDQSXg4yJzyT"

# specific api call info
rdeck_job="0745efe5-17c2-44cd-bb59-26706331ea2f"
rdeck_filter="node01"
option_value="YOUR_VALUE"

# api call
curl --location --request POST "$protocol://$rdeck_host:$rdeck_port/api/$rdeck_api/job/$rdeck_job/run" \
  --header "Accept: application/$format" \
  --header "X-Rundeck-Auth-Token: $rdeck_token" \
  --header "Content-Type: application/$format" \
  --data "{ \"argString\":\"-opt1 $option_value \", \"filter\":\"$rdeck_filter\" }"

它适用于以下作业定义示例:

- defaultTab: nodes
  description: ''
  executionEnabled: true
  id: f2dc19f0-b099-46c6-a50d-a6848797851d
  loglevel: INFO
  name: HelloWorld
  nodeFilterEditable: false
  nodefilters:
    dispatch:
      excludePrecedence: true
      keepgoing: false
      rankOrder: ascending
      successOnEmptyNodeFilter: false
      threadcount: '1'
    filter: ''
  nodesSelectedByDefault: true
  options:
  - name: opt1
  plugins:
    ExecutionLifecycle: null
  scheduleEnabled: true
  sequence:
    commands:
    - exec: echo "hola ${option.opt1}"
    keepgoing: false
    strategy: node-first
  uuid: f2dc19f0-b099-46c6-a50d-a6848797851d

相关问题