scm api working examples

641 views
Skip to first unread message

edt

unread,
Aug 22, 2018, 7:14:49 PM8/22/18
to rundeck-discuss


Can anyone point me to working code samples for the native SCM plugins to import and export jobs.
I am currently exporting and importing to my git repo via the web console and all working fine.
I'm looking to edit jobs via the YAML definitions, push to my git repo server, and import the updates.

While the API docs are quite comprehensive, the SCM APIs in particular are quite hard to follow and without examples of the end to end workflow, I'm quite lost.

I'm up to the stage where I have the following command:
$ curl -H 'X-Rundeck-Auth-Token:my-token' -H 'Accept:text/json' https://my.rundeck.com/api/24/project/aws/scm/import/action/remote-pull/input | python -m json.tool
{
    "title": "Pull Remote Changes",
    "exportItems": null,
    "fields": [
        {
            "defaultValue": "1 file(s) need to be imported\n\nPulling from remote branch: `master`",
            "description": null,
            "name": "status",
            "renderingOptions": {
                "displayType": "STATIC_TEXT",
                "staticTextContentType": "text/x-markdown"
            },
            "required": false,
            "scope": null,
            "title": "Git Status",
            "type": "String",
            "values": null
        }
    ],
    "importItems": [],
    "description": "Synch incoming changes from Remote",
    "integration": "import",
    "actionId": "remote-pull"
}

$ curl -H 'X-Rundeck-Auth-Token:my-token -H 'Accept:text/json' -X POST -H 'Content-type:application/json' --data "{'items':'','jobs':[],'deleted':[]}" https://my.rundeck.com/api/24/project/aws/scm/import/action/remote-pull

However, I can't quite follow the docs as to how I should populate the POST payload using the outputs of the first Action-Input call - or even if I am right track with the sequence of API calls.

The last call gives me a HTML response for an Error page but no details of the error.

edt

unread,
Aug 23, 2018, 10:11:54 AM8/23/18
to rundeck-discuss
After a day of experimenting I think I have the flow figured for imports. I'm sure this isn't the most efficient technique so please do share any improvements or suggestions.
  1. Call the project import status api (/api/24/project/aws/scm/import/status)
  2. inspect the actions list in the response from 1.
    {
     
    "project": "aws",
     
    "message": "1 changes from remote need to be pulled",
     
    "synchState": "REFRESH_NEEDED",
     
    "integration": "import",
     
    "actions": [
       
    "remote-pull",
       
    "import-jobs"
     
    ]
    }
  3. Call the remote-pull action api  (/api/24/project/aws/scm/import/action/remote-pull) to perform a git pull on the internal git repo managed by rundeck. From experimentation, the post json payload is still requires one of the valid keys but the values can be empty. It would appear that my error was that I was calling this action when it wasn't required
  4. Success response.
    {"message":"SCM import Action was Successful: remote-pull","nextAction":null,"success":true,"validationErrors":null}

  5. Then call the import-jobs input api (/api/24/project/aws/scm/import/action/import-jobs/input) to get the list of job definition changes
  6. Inspect the list of job status for change
    {
     
    "description": "Import the modifications to Rundeck",
     
    "title": "Import remote Changes",
     
    "fields": [],
     
    "integration": "import",
     
    "actionId": "import-jobs",
     
    "importItems": [
       
    {
         
    "deleted": false,
         
    "itemId": "aws/cloudformation-create-change-set-6707cfa8-3466-4e33-8594-f2e99873c17a.yaml",
         
    "job": {
           
    "jobName": "cloudformation-create-change-set",
           
    "groupPath": null,
           
    "jobId": "e3c6ae60-23b6-4068-8684-97240ad9d7d7"
         
    },
         
    "status": "IMPORT_NEEDED",
         
    "tracked": true
       
    },
       
    {
         
    "deleted": false,
         
    "itemId": "aws/create-ebs-snapshot-d5751ad2-108d-4795-bdac-535164d0da75.yaml",
         
    "job": {
           
    "jobName": "create-ebs-snapshot",
           
    "groupPath": null,
           
    "jobId": "ca434b3f-78c2-49cb-92f8-924fd05bb936"
         
    },
         
    "status": "CLEAN",
         
    "tracked": true
       
    }
     
    ],
     
    "exportItems": null
    }

  7. Create a list of job IDs that have status="IMPORT_NEEDED"
  8. Create a hash/dict specifying the "jobs" key and value being the list from 6.
  9. Call the import-jobs action api (/api/24/project/aws/scm/import/import-job, with the post payload from 7.
    • Important that the payload is a JSON ( e.g. in python using latest requests module, requests.post(url, json=my-jpayload) or you will get a "unable to parse JSON" error 
  10. Success response
    { "validationErrors": null, "message": "SCM import Action was Successful: import-jobs", "nextAction": null, "success": true }

Message has been deleted

edt

unread,
Aug 23, 2018, 8:12:54 PM8/23/18
to rundeck-discuss
step 9 typos: Call the import-jobs action api (/api/24/project/aws/scm/import/action/import-job), with the post payload from 8.
Reply all
Reply to author
Forward
0 new messages