|
1 | 1 | # CircleCI API |
2 | 2 |
|
3 | 3 | * [CircleCI API Developer's Guide](https://circleci.com/docs/2.0/api-developers-guide/) |
| 4 | +* [CircleCI API (v2)](https://circleci.com/docs/api/v2/) |
4 | 5 |
|
5 | 6 | ## Authentication |
6 | 7 |
|
7 | 8 | * generate [Personal API Token](https://app.circleci.com/settings/user/tokens) which is associated with a user |
| 9 | + |
| 10 | +* save token in ```~/.circleci.creds``` formatted like |
| 11 | + |
| 12 | +```ini |
| 13 | +# created 8 Jan '22 - personal access token for Dave |
| 14 | +PERSONAL_API_TOKEN=1234567890abcdef |
| 15 | +``` |
| 16 | + |
| 17 | +* extract using something like |
| 18 | + |
| 19 | +```bash |
| 20 | +~> PERSONAL_API_TOKEN=$(grep PERSONAL_API_TOKEN ~/.circleci.creds | sed -e 's|^.*=||g') |
| 21 | +~> |
| 22 | +``` |
| 23 | + |
8 | 24 | * test the token works |
9 | 25 |
|
10 | 26 | ```bash |
|
81 | 97 | * [Scheduled Pipelines](https://circleci.com/docs/2.0/scheduled-pipelines) |
82 | 98 | * [7 Jan '22 - Getting started with scheduled pipelines](https://circleci.com/blog/using-scheduled-pipelines/) |
83 | 99 | * can configure schedules under ```project settings / triggers``` (ex [https://app.circleci.com/settings/project/github/simonsdave/cloudfeaster/triggers](https://app.circleci.com/settings/project/github/simonsdave/cloudfeaster/triggers)) |
| 100 | +* [Schedule CircleCI API (v2)](https://circleci.com/docs/api/v2/#tag/Schedule) |
84 | 101 |
|
85 | 102 | ### Get All Schedules |
86 | 103 |
|
87 | 104 | ```bash |
88 | 105 | ~> curl \ |
89 | 106 | -s \ |
90 | | - --verbose \ |
91 | 107 | --header "Circle-Token: ${PERSONAL_API_TOKEN}" \ |
92 | 108 | --header 'Accept: application/json' \ |
93 | 109 | https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/schedule |
| 110 | +~> |
94 | 111 | ``` |
95 | 112 |
|
96 | 113 | ### Create Schedule |
|
101 | 118 | ```bash |
102 | 119 | ~> curl \ |
103 | 120 | -s \ |
104 | | - --verbose \ |
105 | 121 | --header "Circle-Token: ${PERSONAL_API_TOKEN}" \ |
106 | 122 | -X POST \ |
107 | 123 | --header 'Content-Type: application/json' \ |
108 | 124 | --data-raw '{ |
109 | | - "name": "Run Integration Tests", |
110 | | - "description": "Run intergration tests every day", |
| 125 | + "name": "Integration Tests", |
| 126 | + "description": "Run Intergration Tests", |
111 | 127 | "attribution-actor": "system", |
112 | 128 | "parameters": { |
113 | 129 | "branch": "master" |
114 | 130 | }, |
115 | 131 | "timetable": { |
116 | 132 | "per-hour": 1, |
117 | | - "hours-of-day": [16], |
| 133 | + "hours-of-day": [21], |
118 | 134 | "days-of-week": ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"] |
119 | 135 | } |
120 | 136 | }' \ |
121 | 137 | --header 'Accept: application/json' \ |
122 | | - https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/schedule |
| 138 | + https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/schedule | jq . |
| 139 | +{ |
| 140 | + "description": "Run Intergration Tests", |
| 141 | + "updated-at": "2022-01-09T20:13:18.855Z", |
| 142 | + "name": "Integration Tests", |
| 143 | + "id": "00000000-1111-2222-3333-444444444444", |
| 144 | + "project-slug": "gh/simonsdave/cloudfeaster", |
| 145 | + "created-at": "2022-01-09T20:13:18.855Z", |
| 146 | + "parameters": { |
| 147 | + "branch": "master" |
| 148 | + }, |
| 149 | + "actor": { |
| 150 | + "login": "system-actor", |
| 151 | + "name": "Scheduled", |
| 152 | + "id": "55555555-1111-2222-3333-444444444444", |
| 153 | + }, |
| 154 | + "timetable": { |
| 155 | + "per-hour": 1, |
| 156 | + "hours-of-day": [ |
| 157 | + 21 |
| 158 | + ], |
| 159 | + "days-of-week": [ |
| 160 | + "MON", |
| 161 | + "TUE", |
| 162 | + "WED", |
| 163 | + "THU", |
| 164 | + "FRI", |
| 165 | + "SAT", |
| 166 | + "SUN" |
| 167 | + ] |
| 168 | + } |
| 169 | +} |
| 170 | +~> |
| 171 | +``` |
| 172 | + |
| 173 | +### Get A Schedule |
| 174 | + |
| 175 | +* get a schedule after it's been created |
| 176 | + |
| 177 | +```bash |
| 178 | +~> curl \ |
| 179 | + -s \ |
| 180 | + --header "Circle-Token: ${PERSONAL_API_TOKEN}" \ |
| 181 | + --header 'Accept: application/json' \ |
| 182 | + https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/schedule/00000000-1111-2222-3333-444444444444 |
| 183 | +~> |
| 184 | +``` |
| 185 | + |
| 186 | +## Delete Schedule |
| 187 | + |
| 188 | +* delete a schedule after it's been created |
| 189 | + |
| 190 | +```bash |
| 191 | +~> curl \ |
| 192 | + -s \ |
| 193 | + --header "Circle-Token: ${PERSONAL_API_TOKEN}" \ |
| 194 | + -X DELETE \ |
| 195 | + --header 'Accept: application/json' \ |
| 196 | + https://circleci.com/api/v2/project/gh/simonsdave/cloudfeaster/schedule/00000000-1111-2222-3333-444444444444 |
| 197 | +~> |
123 | 198 | ``` |
0 commit comments