Skip to content

Commit

Permalink
Update the rest api code
Browse files Browse the repository at this point in the history
  • Loading branch information
anveshmuppeda committed May 4, 2024
1 parent c448d6a commit 1de4f6e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
66 changes: 66 additions & 0 deletions ado-rest-api/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#
## 1. Create a YAML file:
In your code repository, create a YAML file named azure-restapi-pipeline.yaml or any name you prefer.

## Create pipeline json
### Get repository ID
```bash
REPO_ID=$(curl -s -X GET "https://dev.azure.com/$ORGANIZATION/$PROJECT/_apis/git/repositories/$REPOSITORY" -H "Authorization: Basic $PAT" | jq -r '.id')
```

Create apipipeline.json file with the details of pipeline you want to create.
Example:
```json
{
"folder": null,
"name": "pipeline-made-by-api-2",
"configuration": {
"type": "yaml",
"path": "/azure-rest-api-pipeline.yaml",
"repository": {
"id": "eba9d845-71ed-403a-a2ac-a5af2b0d8866",
"name": "azure-devops-series",
"type": "azureReposGit"
}
}
}
```
Replace "name" with the name of your pipeline, "path" with the directory where your pipeline YAML definition exists, "repository/id" with the repository ID, and "repository/name" with the repository name.


## Use Azure DevOps REST API:
You'll need to use the Azure DevOps REST API to create the pipeline. Here's a simplified example using cURL:

### Setting up environment variables
```bash
# Replace placeholders with your actual values
ORGANIZATION="your-organization"
PROJECT="your-project"
REPOSITORY="your-repository"
PAT="your-personal-access-token"
```

### Create pipeline
```bash
curl --user ":$PAT" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
"https://dev.azure.com/$ORGANIZATION/$PROJECT/_apis/pipelines?api-version=6.0-preview.1" \
-d @apipipeline.json
```

Using the above command the pipeline got created, login to azure devops and check the pipeline.

### References
1. https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines/create?view=azure-devops-rest-6.1#createpipelineconfigurationparameters
2. https://johnnyreilly.com/create-pipeline-with-azure-devops-api


Or directly you can use below command to create pipeline.
```bash
curl --user '':'MYPATTOKEN' \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
'https://dev.azure.com/amuppeda/azure-devops-series/_apis/pipelines?api-version=6.1-preview.1' \
-d @apipipeline.json
```
13 changes: 13 additions & 0 deletions ado-rest-api/apipipeline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"folder": null,
"name": "pipeline-made-by-api-2",
"configuration": {
"type": "yaml",
"path": "/azure-rest-api-pipeline.yaml",
"repository": {
"id": "eba9d845-71ed-403a-a2ac-a5af2b0d8866",
"name": "azure-devops-series",
"type": "azureReposGit"
}
}
}

0 comments on commit 1de4f6e

Please sign in to comment.