To create a pipeline, you make a POST request and provide the endpoint ID. Then you use the ID of the pipeline created in a PATCH request to enable it.
Prerequisites
- Verify that all general prerequisites and prerequisites for the Automation Pipelines service have been satisfied. See Prerequisites for API Use Case Examples.
- Verify that you have the ID for the project that you used for your endpoint. See Create a Project with the Project Service API.
- Verify that you know the name of the Jenkins endpoint that you created. See Create an Endpoint.
Procedure
Example: Create and Enable a Pipeline
Using the endpoint named jenkins-example that you created, create a pipeline named jenkinspipeline with a Jenkins task.
Assign variables.
$ url='https://appliance.domain.com'
$ api_version='2019-10-17'
$ project_id='MyProject1'
$ endpoint_name='jenkins-example'
Create the pipeline with a Jenkins task.
$ curl -X POST \ $url/codestream/api/pipelines?apiVersion=$api_version \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $access_token" \ -d '{ "project": "'$project_id'", "kind": "PIPELINE", "name": "jenkinspipeline", "concurrency": 10, "stageOrder": ["Stage0"], "stages": { "Stage0": { "taskOrder": ["Task0"], "tags": [], "tasks": { "Task0": { "type": "Jenkins", "ignoreFailure": false, "preCondition": "", "input": { "job": "Build-DemoApp", "jobFolder": "", "parameters": { "vRCSTestExecutionId": "" } }, "endpoints": { "jenkinsServer": "'$endpoint_name'" }, "tags": [], "_configured": true } } } } }' | jq "."
A snippet of the response shows the pipeline ID and shows the state of the pipeline as disabled.
{ "project": "MyProject1", "kind": "PIPELINE", "id": "2677aa61-578a-4465-a653-a3c787fed3be", "name": "jenkinspipeline", "createdBy": "[email protected]", "updatedBy": "[email protected]", "createdAt": "2022-11-04T11:20:09.905+0000", "updatedAt": "2022-11-04T11:23:40.971+0000", "_link": "/codestream/api/pipelines/2677aa61-578a-4465-a653-a3c787fed3be", ... "rollbacks": [], "tags": [], "state": "DISABLED" }
Assign a variable for the pipeline ID.
$ pipeline_id="2677aa61-578a-4465-a653-a3c787fed3be"
Enable the pipeline.
$ curl -X PATCH \ $url/codestream/api/pipelines/$pipeline_id?apiVersion=$api_version \ -H 'Content-Type: application/json' \ -H "Authorization: Bearer $access_token" \ -d '{"state": "ENABLED"}' | jq "."
A snippet of the response shows the state of the pipeline is enabled.
{ "project": "MyProject1", "kind": "PIPELINE", "id": "2677aa61-578a-4465-a653-a3c787fed3be", "name": "jenkinspipeline", "createdBy": "[email protected]", "updatedBy": "[email protected]", "createdAt": "2022-11-04T11:20:09.905+0000", "updatedAt": "2022-11-04T11:24:50.693+0000", "_link": "/codestream/api/pipelines/2677aa61-578a-4465-a653-a3c787fed3be", ... "rollbacks": [], "tags": [], "state": "ENABLED" }
What to do next
Run your pipeline.