-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Git lab add trigger pipeline command #27544
Changes from 200 commits
ded6610
fa60a6b
0a53654
2c2e84a
7ee746d
5af02dd
e5499a8
a210308
01019cb
aab5e0a
4e6b036
aeedc41
7cd2d79
5820f25
1c969be
051c85f
54c3d0e
728a210
d1b716e
11556e2
391d3e9
9097c61
959f618
f9bfaff
6f9526d
0d08153
ede878f
1867af8
bbc7ad4
09edd70
bc0f904
4417743
1930999
f0e5f90
990108e
5831282
8573d5a
b6aee7c
a5e6f80
d002b82
d487593
b37a09c
69deea8
b2c2229
9d5f131
d39f2d7
dec93b1
0d2fa5c
7053fa9
db58f34
206b6f9
93cfa1b
032561d
c64ff28
a60a26a
afaf226
5cc6551
7a99368
f325f78
9da2a23
759c4c5
026e28d
f4ad51a
f9976e7
b58ed13
f5dcdfd
bebe153
46d10f3
d3affce
41747ce
79fe635
66c522b
784514f
bec2a99
4090fc7
31a3ac6
9699197
ab1aa7d
ef62077
0a599a4
9f9a35f
245d5ee
2005156
b99e265
cab47d2
a996359
30d44b3
ae85c46
9bc7982
e55015a
43edd80
6edd044
45b740f
3aebd94
13994e8
d3a1536
21616fc
43eb25f
41e60cf
c03511d
95a6e2c
c27826d
8d1bf8f
53eaeb4
c182789
4071cd4
1d7d958
d36d987
6f5cd97
030ce31
71e4c0e
636deda
f9899a4
4f28a77
2c3360f
0cd05c2
e16bd7d
f160261
07a399b
821d914
45f4ccc
7bb0d68
5acef60
3e7cfc1
63dd646
e9cb0ca
3765546
c7ffdf2
5c49730
d43983e
d552ec7
e6c2fd6
22b7ce5
ef5a775
8fcc748
fe38f21
369d886
f5609c6
0375677
60fe988
0b69176
a9b2b29
03b66ae
39a72f9
ce91c16
bbf371f
c6f326b
6567d81
b43ae93
96ed2b8
672f42b
c5aa066
32553b6
e1760a8
9c5388f
020f749
1940b63
788ee2a
1dbec69
7472a77
ab82488
d9786b9
2dd3af2
bfdbaa2
9e62e5b
83fc7ac
418f854
687ad0c
5e6d1b2
0ce3977
c8b9078
b310d8c
9f02c7d
62d7359
e96a65d
340a923
9646d79
2e9e2d0
e20ae79
3308b1e
421fd37
ab9fe95
7e513a0
f1203d7
703a0fb
384eab3
a146560
5005b2e
bed032c
492bb9d
ae1b877
653dafb
e5f1721
8956094
e62029b
81f894b
5811533
de430be
0baf7ca
1b7c318
cca6668
ecccb5c
a385519
86542bf
fc3c979
1fbac5a
ef6e776
25dcb32
c1fd085
db145c0
e06f86d
c9c7469
8ff468d
10a7fb1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -986,3 +986,45 @@ def test_return_date_arg_as_iso(arg, isValidDate, expected_response): | |||||
return_date_arg_as_iso(arg) | ||||||
|
||||||
assert str(e.value) == expected_response | ||||||
|
||||||
|
||||||
@pytest.mark.parametrize('trigger_token, args, expected_result', [ | ||||||
('', {}, util_load_json('test_data/commands_test_data.json').get('trigger_pipeline1')), | ||||||
(1111, {'project_id': 2222, 'ref_branch': 'test'}, util_load_json('test_data/commands_test_data.json').get('trigger_pipeline2')) | ||||||
]) | ||||||
def test_trigger_pipeline(mocker, trigger_token, args, expected_result): | ||||||
bziser marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
""" | ||||||
Given: | ||||||
- client and demisto args | ||||||
- case 1 - client without trigger token. | ||||||
- case 2 - client with trigger token and args with a different project ID than the instance. | ||||||
When: | ||||||
- gitlab_trigger_pipeline_command | ||||||
Then: | ||||||
- The response is as expected | ||||||
- case 1 - Throws an error about the trigger token that is missing | ||||||
- case 2 - The response is correct with the same branch and project_id as in the args. | ||||||
""" | ||||||
from GitLabv2 import Client, gitlab_trigger_pipeline_command | ||||||
client = Client(project_id=1234, | ||||||
base_url="base_url", | ||||||
verify=False, | ||||||
proxy=False, | ||||||
headers={'PRIVATE-TOKEN': 'api_key'}, | ||||||
trigger_token=trigger_token) | ||||||
expected_outputs: List[Dict] = expected_result['expected_outputs'] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
expected_prefix: str = expected_result['expected_prefix'] | ||||||
expected_key_field: str = expected_result['expected_key_field'] | ||||||
mocker.patch.object(Client, '_http_request', return_value=expected_result['mock_response']) | ||||||
mock_error = mocker.patch('GitLabv2.return_error') | ||||||
|
||||||
command_result = gitlab_trigger_pipeline_command(client, args) | ||||||
|
||||||
if not trigger_token: | ||||||
assert mock_error.call_args[0][0] == 'A trigger token is required in the integration instance configuration' | ||||||
else: | ||||||
assert command_result.outputs_prefix == expected_prefix | ||||||
assert command_result.outputs_key_field == expected_key_field | ||||||
assert command_result.outputs == expected_outputs | ||||||
assert command_result.outputs.get('ref') == args.get('ref_branch') | ||||||
assert command_result.outputs.get('project_id') == args.get('project_id') |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ This integration enables you to: | |||||||||
- Get a list of files in the GitLab project. | ||||||||||
- Get the contents and details of a file in GitLab. | ||||||||||
- Search for code in the GitLab project. | ||||||||||
- Trigger a pipeline in the GitLab project. | ||||||||||
|
||||||||||
#### Create a Personal Access Token | ||||||||||
Personal access tokens (PATs) are an alternative to using passwords for authentication to GitLab when using the GitLab API. | ||||||||||
|
@@ -28,6 +29,18 @@ To generate a new token: | |||||||||
6. Select the **scopes**, or **permissions**, you want to grant this token. The minimum is read-only on repo. | ||||||||||
7. Click **Create personal access token** and copy the api key generated.-+ | ||||||||||
|
||||||||||
#### Create a Trigger Token | ||||||||||
Trigger tokens allows you to trigger a pipeline for a branch using it to authenticate on an API call. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
Prerequisite: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
- You must have at least the Maintainer role for the project. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
To generate a new token: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
1. Navigate to your project. | ||||||||||
2. Select Settings > CI/CD. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
3. Expand Pipeline triggers. | ||||||||||
4. Enter a description and select Add trigger. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
- You can view and copy the full token for all triggers you have created. | ||||||||||
- You can only see the first 4 characters for tokens created by other project members. | ||||||||||
|
||||||||||
#### Get Project ID | ||||||||||
1. Go to the desired project example gitlab.com/username/project1. | ||||||||||
2. Under the project name get the argument project_id | ||||||||||
|
@@ -42,6 +55,7 @@ To generate a new token: | |||||||||
| --- | --- | --- | | ||||||||||
| Server URL (e.g. https://gitlab.com/api/v4) | | False | | ||||||||||
| API Key | The API Key to use for connection | True | | ||||||||||
| Trigger Token | The trigger token to run pipelines | False | | ||||||||||
| Project ID | | True | | ||||||||||
| Trust any certificate (not secure) | | False | | ||||||||||
| Use system proxy settings | | False | | ||||||||||
|
@@ -2144,3 +2158,42 @@ Gets an artifact from a given artifact path, corresponding to a given job ID. | |||||||||
| GitLab.Artifact.job_id | String | Job ID from which the artifact was taken. | | ||||||||||
| GitLab.Artifact.artifact_path_suffix | String | Suffix of the given artifact path. | | ||||||||||
| GitLab.Artifact.artifact_data | String | Data of the artifact requested. | | ||||||||||
|
||||||||||
### gitlab-trigger-pipeline | ||||||||||
|
||||||||||
*** | ||||||||||
Triggers a GitLab pipeline on a selected project and branch. | ||||||||||
|
||||||||||
#### Base Command | ||||||||||
|
||||||||||
`gitlab-trigger-pipeline` | ||||||||||
|
||||||||||
#### Input | ||||||||||
|
||||||||||
| **Argument Name** | **Description** | **Required** | | ||||||||||
| --- | --- | --- | | ||||||||||
| project_id | Project ID on which to run the pipeline. | Optional | | ||||||||||
| ref_branch | The branch on which to run the pipeline. Default is 'master'. | Optional | | ||||||||||
| trigger_variables | JSON containing the pipeline variables. | Optional | | ||||||||||
|
||||||||||
#### Context Output | ||||||||||
|
||||||||||
| **Path** | **Type** | **Description** | | ||||||||||
| --- | --- | --- | | ||||||||||
| GitLab.Pipeline.id | Number | Pipeline ID. | | ||||||||||
| GitLab.Pipeline.project_id | Number | Project ID that the pipeline belongs to. | | ||||||||||
| GitLab.Pipeline.status | String | Status of the pipeline. | | ||||||||||
| GitLab.Pipeline.ref | String | Reference of the pipeline. | | ||||||||||
| GitLab.Pipeline.sha | String | SHA of the pipeline. | | ||||||||||
| GitLab.Pipeline.created_at | Date | Time when the pipeline was created. | | ||||||||||
| GitLab.Pipeline.updated_at | Date | Time when the pipeline was last updated. | | ||||||||||
| GitLab.Pipeline.started_at | Date | Time when the pipeline was started. | | ||||||||||
| GitLab.Pipeline.finished_at | Date | Time when the pipeline was finished. | | ||||||||||
| GitLab.Pipeline.duration | Number | Duration of the pipeline in seconds. | | ||||||||||
| GitLab.Pipeline.web_url | String | Web URL of the pipeline. | | ||||||||||
| GitLab.Pipeline.user.name | String | Name of the user who triggered the pipeline. | | ||||||||||
| GitLab.Pipeline.user.username | String | Username that triggered the pipeline. | | ||||||||||
| GitLab.Pipeline.user.id | Number | ID of the user who triggered the pipeline. | | ||||||||||
| GitLab.Pipeline.user.state | String | State of the user who triggered the pipeline. | | ||||||||||
| GitLab.Pipeline.user.avatar_url | String | Avatar URL of the user who trigerred the pipeline. | | ||||||||||
| GitLab.Pipeline.user.web_url | String | Web URL of the user who triggered the pipeline. | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
#### Integrations | ||
##### GitLab v2 | ||
Added the new ***gitlab-trigger-pipeline*** command to trigger a GitLab pipeline. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.