Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules documentation #2932

Merged
merged 40 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5c4daee
New rules page
clbarrell Aug 15, 2024
700dda9
First pass editing Rules docs
matthewborden Aug 21, 2024
33b6495
Update pages/pipelines/rules.md
matthewborden Aug 22, 2024
b647b89
Update pages/pipelines/rules.md
matthewborden Aug 22, 2024
6d18085
Update pages/pipelines/rules.md
matthewborden Aug 22, 2024
0139de3
Update pages/pipelines/rules.md
matthewborden Aug 22, 2024
b381f73
Update pages/pipelines/rules.md
matthewborden Aug 22, 2024
35fb71a
Update pages/pipelines/rules.md
matthewborden Aug 22, 2024
df7cc28
Update pages/pipelines/rules.md
matthewborden Aug 22, 2024
906e418
Add extra detail about rules.
l-suzuki Aug 26, 2024
dd804d9
Refine rules docs
l-suzuki Aug 26, 2024
e1dc435
Add rest api docs
l-suzuki Aug 26, 2024
44cc892
Add rules to the nav, restructure into sections.
l-suzuki Aug 26, 2024
134ef8f
Add descriptions for finding pipeline and rule uuids for api calls
l-suzuki Aug 26, 2024
d2a0775
Add descriptions for rule and pipeline uuids
l-suzuki Aug 26, 2024
e3d531b
Add cookbook for rules
l-suzuki Aug 26, 2024
45db920
Add rule cookbook to graphql nav
l-suzuki Aug 26, 2024
9c700f9
UI -> interface
l-suzuki Aug 26, 2024
bdc8bc7
Run bundle exec rake graphql:generate
l-suzuki Aug 26, 2024
6cfada1
Fix url links and typos, rename triggered/triggering to source/target…
l-suzuki Aug 27, 2024
8dcc18b
Flesh out example use cases
l-suzuki Aug 29, 2024
cd0d595
Fix broken links, renumber steps, and remove formatting from headings.
gilesgas Aug 30, 2024
fb19e46
Add Rules entry for GraphQL Cookbook and fix more linting issues.
gilesgas Aug 30, 2024
66b105d
Remove extra line endings from end of Rules GraphQL page.
gilesgas Aug 30, 2024
5bfacf7
Add missing link to GraphQL Cookbooks Overview page.
gilesgas Aug 30, 2024
2c6282c
Ran rake to rebuild the GraphQL nav.
gilesgas Aug 30, 2024
443c430
Merge remote-tracking branch 'docs-public/main' into pipeline-rules
gilesgas Aug 30, 2024
5158fbe
Add spec test for Rules entry.
gilesgas Sep 1, 2024
159304b
Complete t/w review of rules overview page.
gilesgas Sep 2, 2024
05db421
Restructure rules landing page to remove '/overview' requirement from…
gilesgas Sep 3, 2024
36de2d4
Fix broken links.
gilesgas Sep 3, 2024
d07d378
Fix up Manage rules page. And a few more tweaks to the rules landing …
gilesgas Sep 3, 2024
f341749
Fix pedantic linter.
gilesgas Sep 3, 2024
bcd9193
Final tweaks to rules' feature's API pages. Fix GraphQL query syntax …
gilesgas Sep 4, 2024
0c10f0e
Streamline rules intro a little more.
gilesgas Sep 4, 2024
472eaa5
More intro tweaks and fix another typo in GraphQL query.
gilesgas Sep 4, 2024
0791802
Add 'early access' note to top of Rules overview page.
gilesgas Sep 5, 2024
b821699
Fix terminology around hash > JSON object, and tweak early access not…
gilesgas Sep 5, 2024
0d8bab0
Fix typo.
gilesgas Sep 5, 2024
5a32705
Minor sentence tweak to make it read less clunkily.
gilesgas Sep 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@
path: "pipelines/hosted-agents/pipeline-migration"
- name: "Terminal access"
path: "pipelines/hosted-agents/terminal-access"
- name: "Rules"
children:
- name: "Overview"
path: "pipelines/rules"
- name: "Manage rules"
path: "pipelines/rules/manage"
- name: "Security"
children:
- name: "Overview"
Expand Down Expand Up @@ -575,6 +581,8 @@
path: "apis/rest-api/meta"
- name: "Pipeline templates"
path: "apis/rest-api/pipeline-templates"
- name: "Rules"
path: "apis/rest-api/rules"
- name: "User"
path: "apis/rest-api/user"
- name: "Teams"
Expand Down
2 changes: 2 additions & 0 deletions data/nav_graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
path: apis/graphql/cookbooks/pipelines
- name: Pipeline templates
path: apis/graphql/cookbooks/pipeline-templates
- name: Rules
path: apis/graphql/cookbooks/rules
- name: Organizations
path: apis/graphql/cookbooks/organizations
- name: Teams
Expand Down
2 changes: 1 addition & 1 deletion pages/apis/descriptions/_graphql_organization_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
```graphql
query getCurrentUsersOrgs {
viewer {
organization {
organizations {
edges {
node {
name
Expand Down
2 changes: 1 addition & 1 deletion pages/apis/descriptions/_rest_access_token.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- `$TOKEN` is an [API access token](https://buildkite.com/user/api-access-tokens) scoped to the relevant **Organization** and **REST API Scopes** that your agent needs access to in Buildkite.
- `$TOKEN` is an [API access token](https://buildkite.com/user/api-access-tokens) scoped to the relevant **Organization** and **REST API Scopes** that your request needs access to in Buildkite.
94 changes: 94 additions & 0 deletions pages/apis/graphql/cookbooks/rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Rules
gilesgas marked this conversation as resolved.
Show resolved Hide resolved

A collection of common tasks with rules using the GraphQL API.

You can test out the Buildkite GraphQL API using the [Buildkite explorer](https://graphql.buildkite.com/explorer). This includes built-in documentation under the **Docs** panel.

## List rules

Get the first 10 rules and their information for an organization.

```graphql
query getRules {
organization(slug: "organization-slug") {
rules(first: 10) {
edges {
node {
id
type
targetType
sourceType
source {
... on Pipeline {
slug
}
}
target {
... on Pipeline {
slug
}
}
effect
action
createdBy {
id
name
}
}
}
}
}
}
```

## Create a rule

Create a rule. The value of the `value` field must be a JSON-encoded string.

```graphql
mutation {
ruleCreate(input: {
organizationId: "organization-id",
type: "pipeline.trigger_build.pipeline",
value: "{\"source_pipeline_uuid\":\"{uuid-of-source-pipeline}\",\"target_pipeline_uuid\":\"{uuid-of-target-pipeline}\"}"
}) {
rule {
id
type
targetType
sourceType
source {
... on Pipeline {
uuid
}
}
target {
... on Pipeline {
uuid
}
}
effect
action
createdBy {
id
name
}
}
}
}
```

## Delete a rule

Delete a rule:

```graphql
mutation {
ruleDelete(input: {
organizationId: "organization-id",
id: "rule-id"
}) {
deletedRuleId
}
}
```
1 change: 1 addition & 0 deletions pages/apis/graphql/graphql_cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ There are recipes for a range of different topics, including:
- [Packages](/docs/apis/graphql/cookbooks/packages)
- [Pipelines](/docs/apis/graphql/cookbooks/pipelines)
- [Pipeline templates](/docs/apis/graphql/cookbooks/pipeline-templates)
- [Rules](/docs/apis/graphql/cookbooks/rules)
- [Organizations](/docs/apis/graphql/cookbooks/organizations)
- [Teams](/docs/apis/graphql/cookbooks/teams)
180 changes: 180 additions & 0 deletions pages/apis/rest_api/rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# Rules API

The rules API lets you create and manage rules in your organization.

## Rules

[_Rules_](/docs/pipelines/rules) is a Buildkite feature that can do the following:

<%= render_markdown partial: 'pipelines/rules_summary' %>

### List rules

Returns a [paginated list](<%= paginated_resource_docs_url %>) of an organization's rules.

```bash
curl -H "Authorization: Bearer $TOKEN" \
-X GET "https://api.buildkite.com/v2/organizations/{org.slug}/rules"
```

```json
[
{
"uuid": "42f1a7da-812d-4430-93d8-1cc7c33a6bcf",
"graphql_id": "Q2x1c3Rlci0tLTQyZjFhN2RhLTgxMmQtNDQzMC05M2Q4LTFjYzdjMzNhNmJjZg==",
"organization_uuid": "f02d6a6f-7a0e-481d-9d6d-89b427aec48d",
"url": "http://api.buildkite.com/v2/organizations/acme-inc/rules/42f1a7da-812d-4430-93d8-1cc7c33a6bcf",
"type": "pipeline.trigger_build.pipeline",
"source_type": "pipeline",
"source_uuid": "16f3b56f-4934-4546-923c-287859851332",
"target_type": "pipeline",
"target_uuid": "d07d5d84-d1bd-479c-902c-ce8a01ce5aac",
"effect": "allow",
"action": "trigger_build",
"created_at": "2024-08-26T03:22:45.555Z",
"created_by": {
"id": "3d3c3bf0-7d58-4afe-8fe7-b3017d5504de",
"graphql_id": "VXNlci0tLTNkM2MzYmYwLTdkNTgtNGFmZS04ZmU3LWIzMDE3ZDU1MDRkZQo=",
"name": "Sam Kim",
"email": "[email protected]",
"avatar_url": "https://www.gravatar.com/avatar/example",
"created_at": "2013-08-29T10:10:03.000Z"
}
}
]
```

Required scope: `read_rules`

Success response: `200 OK`

### Get a rule

```bash
curl -H "Authorization: Bearer $TOKEN" \
-X GET "https://api.buildkite.com/v2/organizations/{org.slug}/rules/{uuid}"
```

```json
{
"uuid": "42f1a7da-812d-4430-93d8-1cc7c33a6bcf",
"graphql_id": "Q2x1c3Rlci0tLTQyZjFhN2RhLTgxMmQtNDQzMC05M2Q4LTFjYzdjMzNhNmJjZg==",
"organization_uuid": "f02d6a6f-7a0e-481d-9d6d-89b427aec48d",
"url": "http://api.buildkite.com/v2/organizations/acme-inc/rules/42f1a7da-812d-4430-93d8-1cc7c33a6bcf",
"type": "pipeline.trigger_build.pipeline",
"source_type": "pipeline",
"source_uuid": "16f3b56f-4934-4546-923c-287859851332",
"target_type": "pipeline",
"target_uuid": "d07d5d84-d1bd-479c-902c-ce8a01ce5aac",
"effect": "allow",
"action": "trigger_build",
"created_at": "2024-08-26T03:22:45.555Z",
"created_by": {
"id": "3d3c3bf0-7d58-4afe-8fe7-b3017d5504de",
"graphql_id": "VXNlci0tLTNkM2MzYmYwLTdkNTgtNGFmZS04ZmU3LWIzMDE3ZDU1MDRkZQo=",
"name": "Sam Kim",
"email": "[email protected]",
"avatar_url": "https://www.gravatar.com/avatar/example",
"created_at": "2013-08-29T10:10:03.000Z"
}
}
```

Required scope: `read_rules`

Success response: `200 OK`

### Create a rule

```bash
curl -H "Authorization: Bearer $TOKEN" \
-X POST "https://api.buildkite.com/v2/organizations/{org.slug}/rules" \
-H "Content-Type: application/json" \
-d '{
"type": "pipeline.trigger_build.pipeline",
"value": {
"source_pipeline_uuid": "16f3b56f-4934-4546-923c-287859851332",
"target_pipeline_uuid": "d07d5d84-d1bd-479c-902c-ce8a01ce5aac"
}
}'
```

```json
{
"uuid": "42f1a7da-812d-4430-93d8-1cc7c33a6bcf",
"graphql_id": "Q2x1c3Rlci0tLTQyZjFhN2RhLTgxMmQtNDQzMC05M2Q4LTFjYzdjMzNhNmJjZg==",
"organization_uuid": "f02d6a6f-7a0e-481d-9d6d-89b427aec48d",
"url": "http://api.buildkite.com/v2/organizations/acme-inc/rules/42f1a7da-812d-4430-93d8-1cc7c33a6bcf",
"type": "pipeline.trigger_build.pipeline",
"source_type": "pipeline",
"source_uuid": "16f3b56f-4934-4546-923c-287859851332",
"target_type": "pipeline",
"target_uuid": "d07d5d84-d1bd-479c-902c-ce8a01ce5aac",
"effect": "allow",
"action": "trigger_build",
"created_at": "2024-08-26T03:22:45.555Z",
"created_by": {
"id": "3d3c3bf0-7d58-4afe-8fe7-b3017d5504de",
"graphql_id": "VXNlci0tLTNkM2MzYmYwLTdkNTgtNGFmZS04ZmU3LWIzMDE3ZDU1MDRkZQo=",
"name": "Sam Kim",
"email": "[email protected]",
"avatar_url": "https://www.gravatar.com/avatar/example",
"created_at": "2013-08-29T10:10:03.000Z"
}
}
```

Required [request body properties](/docs/api#request-body-properties):

<table class="responsive-table">
<tbody>
<tr>
<th><code>type</code></th>
<td>The rule type. Must match one of the <a href="/docs/pipelines/rules#rule-types">available rule types</a>.<br>
Copy link
Contributor

@gilesgas gilesgas Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI only (for future docs contributions) ... Markdown syntax does not render into HTML, when this syntax is used within HTML tables in a Markdown file.

Therefore, I had to convert this Markdown link into its HTML equivalent.

<em>Example:</em>
<ul>
<li><code>"pipeline.trigger_build.pipeline"</code><br/>or</li>
<li><code>"pipeline.artifacts_read.pipeline"</code></li>
</td>
</tr>
<tr>
<th><code>value</code></th>
<td>A hash containing the value fields for the rule.<br>
<em>Example:</em> <code>{"source_pipeline_uuid": "16f3b56f-4934-4546-923c-287859851332", "target_pipeline_uuid": "d07d5d84-d1bd-479c-902c-ce8a01ce5aac"}</code></td>
gilesgas marked this conversation as resolved.
Show resolved Hide resolved
</tr>
</tbody>
</table>

Required scope: `write_rules`

Success response: `201 Created`

Error responses:

<table class="responsive-table">
<tbody>
<tr><th><code>422 Unprocessable Entity</code></th><td><code>{ "message": "Reason for failure" }</code></td></tr>
</tbody>
</table>

### Delete a rule

Delete a rule.

```bash
curl -H "Authorization: Bearer $TOKEN" \
-X DELETE "https://api.buildkite.com/v2/organizations/{org.slug}/rules/{uuid}"
```

Required scope: `write_rules`

Success response: `204 No Content`

Error responses:

<table class="responsive-table">
<tbody>
<tr><th><code>422 Unprocessable Entity</code></th><td><code>{ "message": "Reason the rule couldn't be deleted" }</code></td></tr>
</tbody>
</table>

4 changes: 2 additions & 2 deletions pages/clusters/manage_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ where:
1. Select **Pipelines** in the global navigation > the specific pipeline to be moved to the cluster > **Settings**.
1. Copy the **ID** shown in the **GraphQL API Integration** section of this page, which is this `id` value.

* By running the `getCurrentUsersOrgs` GraphQL API query to obtain the organization slugs for the current user's accessible organizations, [getOrgPipelines](/docs/apis/graphql/schemas/query/organization) query to obtain the pipeline's `id` in the response. For example:
* By running the `getCurrentUsersOrgs` GraphQL API query to obtain the organization slugs for the current user's accessible organizations, then [getOrgPipelines](/docs/apis/graphql/schemas/query/organization) query to obtain the pipeline's `id` in the response. For example:

Step 1. Run `getCurrentUsersOrgs` to obtain the organization slug values in the response for the current user's accessible organizations:

Expand Down Expand Up @@ -383,7 +383,7 @@ where:
uuid
name
}
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pages/clusters/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ You can create as many clusters as your require for your setup.

Learn more about working with clusters in [Manage clusters](/docs/clusters/manage-clusters).

>📘 Pipeline triggering
> Pipelines associated with one cluster cannot trigger pipelines associated with another cluster
> 📘 Pipeline triggering
> Pipelines associated with one cluster cannot trigger pipelines associated with another cluster, unless a [rule](/docs/pipelines/rules) has been created to explicitly allow triggering between pipelines in different clusters.

### How should I structure my queues

Expand Down
3 changes: 3 additions & 0 deletions pages/pipelines/_rules_summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Grant access between Buildkite resources that would normally be restricted by [cluster](/docs/clusters/overview), [visibility](/docs/pipelines/public-pipelines), or [permissions](/docs/team-management/permissions).

- Allow an action (for example, triggering a build) between a source resource (for example, a pipeline) and a target resource (for example, another pipeline) across your Buildkite organization.
Loading
Loading