|
7 | 7 | [](LICENSE) |
8 | 8 | [](https://github.com/chris-peterson/pwsh-gitlab/actions/workflows/ci.yml) |
9 | 9 |
|
10 | | - Interact with [GitLab](https://about.gitlab.com/) via [PowerShell](https://github.com/powershell/powershell#-powershell) |
| 10 | +Interact with [GitLab](https://about.gitlab.com/) via [PowerShell](https://github.com/powershell/powershell#-powershell). |
11 | 11 |
|
12 | | -## Getting Started |
| 12 | +📖 **[Full Documentation](https://chris-peterson.github.io/pwsh-gitlab)** — Browse cmdlets, examples, and guides. |
13 | 13 |
|
14 | | -### Module |
| 14 | +## Installation |
| 15 | + |
| 16 | +### PowerShell Gallery |
15 | 17 |
|
16 | 18 | ```powershell |
17 | 19 | Install-Module -Name GitlabCli |
18 | 20 | ``` |
19 | 21 |
|
20 | | -### Docker Image |
| 22 | +### Docker |
21 | 23 |
|
22 | 24 | ```sh |
23 | 25 | docker run -it ghcr.io/chris-peterson/pwsh-gitlab/gitlab-cli |
24 | 26 | ``` |
25 | 27 |
|
26 | | -### Configuration |
27 | | - |
28 | | -#### Environment Variables |
29 | | - |
30 | | -##### `$env:GITLAB_ACCESS_TOKEN` |
31 | | - |
32 | | -Obtain a "Personal Access Token" (PAT) for your GitLab instance |
33 | | - |
34 | | -`https://<your gitlab instance>/-/profile/personal_access_tokens` |
35 | | - |
36 | | -<img width=600 src="PersonalAccessToken.jpg"/> |
37 | | - |
38 | | -Make the value available via |
39 | | - |
40 | | -`$env:GITLAB_ACCESS_TOKEN='<your pat>'`. |
41 | | - |
42 | | -One way to do this would be to add a line to your `$PROFILE` |
43 | | - |
44 | | -##### `$env:GITLAB_URL` |
45 | | - |
46 | | -(Optional) If using a gitlab instance that is not `gitlab.com`, provide it via: |
47 | | - |
48 | | -`$env:GITLAB_URL='<your gitlab instance>'` |
49 | | - |
50 | | -#### Example PowerShell Profile |
51 | | - |
52 | | -```powershell |
53 | | -$env:GITLAB_URL='gitlab.mydomain.com' |
54 | | -$env:GITLAB_ACCESS_TOKEN='<my token>' |
55 | | -Import-Module GitlabCli |
56 | | -``` |
57 | | - |
58 | | -#### Configuration File |
59 | | - |
60 | | -The following commands can be used to configure your system for use with **multiple** gitlab sites. |
61 | | - |
62 | | -* `Add-GitlabSite` |
63 | | -* `Remove-GitlabSite` |
64 | | -* `Set-DefaultGitlabSite` |
65 | | - |
66 | | -## Common Parameters: Paging |
67 | | - |
68 | | -The following parameters control pagination for query operations: |
69 | | - |
70 | | -| Parameter | Description | |
71 | | -| --- | --- | |
72 | | -| `-MaxPages` | Maximum number of pages to return _(default: `$global:GitlabDefaultMaxPages`)_ | |
73 | | -| `-All` | Return all pages. _NOTE:_ Overrides `-MaxPages` | |
74 | | -| `-Recurse` | Recurse child objects (e.g. `Get-GitlabProject -GroupId 'mygroup' -Recurse`). _NOTE:_ Implies `-All` pages | |
75 | | - |
76 | | -## Common Parameters: Safety |
77 | | - |
78 | | -Mutable operations in this module support ["should process"](https://learn.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-shouldprocess?view=powershell-7.5). |
79 | | - |
80 | | -| Parameter | Description | |
81 | | -| --- | --- | |
82 | | -| `-WhatIf` | Preview what actions would be taken without executing them | |
83 | | -| `-Confirm` | Prompt for confirmation before executing mutable operations | |
84 | | - |
85 | | -## Common Parameters: Navigation |
86 | | - |
87 | | -The following parameters control post-operation behavior: |
88 | | - |
89 | | -| Parameter | Description | |
90 | | -| --- | --- | |
91 | | -| `-Follow` | For operations that create a resource, follow the URL after creation | |
92 | | -| `-Wait` | For long-running operations (e.g. running a job/pipeline), wait for operation to complete. In the meantime, the status is polled and reported to the terminal | |
93 | | - |
94 | | -## Common Parameters: Other |
95 | | - |
96 | | -The following parameters are supported when possible: |
97 | | - |
98 | | -| Parameter | Description | |
99 | | -| --- | --- | |
100 | | -| `-Select` | Select subset of response. A shortcut for `\| Select-Object -ExpandProperty`. _NOTE:_ can select multiple properties (comma-separated) | |
101 | | -| `-SiteUrl` | Override site url _(default: inferred from local git context)_ | |
102 | | - |
103 | | -## Global Behaviors |
104 | | - |
105 | | -If invoking commands from within a git repository, `.` can be used for `ProjectId` / `BranchName` to use the local context. |
106 | | - |
107 | | -Most objects returned from commands have a `Url` property. This makes it so you can pipe one or more objects to `Open-InBrowser` (aka `go`) |
108 | | - |
109 | | -## Examples |
110 | | - |
111 | | -### Groups |
112 | | - |
113 | | -#### `Get-GitlabGroup` |
114 | | - |
115 | | -```powershell |
116 | | -Get-GitlabGroup 'mygroup' |
117 | | -``` |
118 | | - |
119 | | -```plaintext |
120 | | - ID Name Url |
121 | | - -- ---- --- |
122 | | - 23 mygroup https://gitlab.mydomain.com/mygroup |
123 | | -``` |
124 | | - |
125 | | -#### `Remove-GitlabGroup` |
126 | | - |
127 | | -```powershell |
128 | | -Remove-GitlabGroup 'mygroup' |
129 | | -``` |
| 28 | +## Quick Start |
130 | 29 |
|
131 | | -#### `Clone-GitlabGroup` (aka `Copy-GitlabGroupToLocalFileSystem`) |
| 30 | +### 1. Get a Personal Access Token |
132 | 31 |
|
133 | | -```powershell |
134 | | -Clone-GitlabGroup 'mygroup' |
135 | | -``` |
| 32 | +Create a PAT at `https://<your-gitlab-instance>/-/profile/personal_access_tokens` |
136 | 33 |
|
137 | | -### Projects |
| 34 | +### 2. Configure |
138 | 35 |
|
139 | | -#### `Get-GitlabProject` (by id) |
| 36 | +**Option A: Environment Variables** (simple) |
140 | 37 |
|
141 | 38 | ```powershell |
142 | | -Get-GitlabProject 'mygroup/myproject' |
143 | | -# OR |
144 | | -Get-GitlabProject 42 |
145 | | -# OR |
146 | | -Get-GitlabProject # use local context |
| 39 | +$env:GITLAB_ACCESS_TOKEN = '<your-token>' |
| 40 | +$env:GITLAB_URL = 'gitlab.example.com' # optional, defaults to gitlab.com |
147 | 41 | ``` |
148 | 42 |
|
149 | | -```plaintext |
150 | | - ID Name Group Url |
151 | | - -- ---- ----- --- |
152 | | - 42 myproject mygroup https://gitlab.mydomain.com/mygroup/myproject |
153 | | -``` |
154 | | - |
155 | | -#### `Get-GitlabProject` (by group) |
| 43 | +**Option B: Configuration File** (multiple sites) |
156 | 44 |
|
157 | 45 | ```powershell |
158 | | -Get-GitlabProject -GroupId 'mygroup/subgroup' |
159 | | -``` |
160 | | - |
161 | | -```plaintext |
162 | | - ID Name Group Url |
163 | | - -- ---- ----- --- |
164 | | - 1 database mygroup/subgroup https://gitlab.mydomain.com/mygroup/subgroup/database |
165 | | - 2 infra mygroup/subgroup https://gitlab.mydomain.com/mygroup/subgroup/infra |
166 | | - 3 service mygroup/subgroup https://gitlab.mydomain.com/mygroup/subgroup/service |
167 | | - 4 website mygroup/subgroup https://gitlab.mydomain.com/mygroup/subgroup/website |
| 46 | +Add-GitlabSite -Url 'https://gitlab.example.com' -AccessToken '<your-token>' -IsDefault |
168 | 47 | ``` |
169 | 48 |
|
170 | | -_Optional Parameters_ |
171 | | - |
172 | | -`-IncludeArchived` - Set this switch to include archived projects. _By default, archived projects are not returned_ |
173 | | - |
174 | | -#### `Transfer-GitlabProject` (aka `Move-GitlabProject`) |
| 49 | +### 3. Start Using |
175 | 50 |
|
176 | 51 | ```powershell |
177 | | -Transfer-GitlabProject -ProjectId 'this-project' -DestinationGroup 'that-group' |
178 | | -``` |
179 | | - |
180 | | -### Merge Requests |
| 52 | +# Get the current project (from local git context) |
| 53 | +Get-GitlabProject |
181 | 54 |
|
182 | | -#### `New-GitlabMergeRequest` |
183 | | - |
184 | | -```powershell |
| 55 | +# Create a merge request from your current branch |
185 | 56 | New-GitlabMergeRequest |
186 | | -``` |
187 | | - |
188 | | -_Optional Parameters_ |
189 | 57 |
|
190 | | -`-ProjectId` - Defaults to local git context |
| 58 | +# Trigger a pipeline |
| 59 | +New-GitlabPipeline |
191 | 60 |
|
192 | | -`-SourceBranch` - Defaults to local git context |
193 | | - |
194 | | -`-TargetBranch` - Defaults to the default branch set in repository config (typically `main`) |
| 61 | +# Search for code |
| 62 | +Search-Gitlab 'TODO' |
| 63 | +``` |
195 | 64 |
|
196 | | -`-Title` - Defaults to space-delimited source branch name |
| 65 | +## Features at a Glance |
197 | 66 |
|
198 | | -## Other Examples |
| 67 | +| Category | What You Can Do | |
| 68 | +|----------|-----------------| |
| 69 | +| **[Projects](https://chris-peterson.github.io/pwsh-gitlab/#/Projects/)** | Create, clone, archive, manage variables and settings | |
| 70 | +| **[Merge Requests](https://chris-peterson.github.io/pwsh-gitlab/#/MergeRequests/)** | Create, review, approve, and merge | |
| 71 | +| **[Pipelines](https://chris-peterson.github.io/pwsh-gitlab/#/Pipelines/)** | Trigger, monitor, and manage CI/CD | |
| 72 | +| **[Groups](https://chris-peterson.github.io/pwsh-gitlab/#/Groups/)** | Organize projects, manage membership | |
| 73 | +| **[And more...](https://chris-peterson.github.io/pwsh-gitlab)** | Issues, Runners, Environments, GraphQL, etc. | |
199 | 74 |
|
200 | | -### `mr` |
| 75 | +## Highlights |
201 | 76 |
|
202 | | -Create or get merge request for current git context |
| 77 | +### Context-Aware Commands |
203 | 78 |
|
204 | | -### Get Deployment |
| 79 | +Run commands from within a git repo — the module automatically detects your project: |
205 | 80 |
|
206 | 81 | ```powershell |
207 | | -Get-GitlabDeployment -Status 'created' -Environment 'nuget.org' |
| 82 | +~/src/myproject> Get-GitlabPipeline -Latest |
| 83 | +~/src/myproject> New-GitlabMergeRequest |
208 | 84 | ``` |
209 | 85 |
|
210 | | -```plaintext |
211 | | - ID Status EnvironmentName Ref CreatedAt |
212 | | - -- ------ --------------- --- --------- |
213 | | - 196679897 created nuget.org main 9/26/2021 5:56:57 AM |
214 | | - ``` |
215 | | - |
216 | | -### Open Web Browser |
| 86 | +### Convenient Aliases |
217 | 87 |
|
218 | 88 | ```powershell |
219 | | -~/src/your-project> Get-GitlabProject | |
220 | | - pipelines -Latest -Branch 'main' -Status 'success' | go |
| 89 | +pipelines # Get-GitlabPipeline |
| 90 | +jobs # Get-GitlabJob |
| 91 | +mr # Get or create merge request |
| 92 | +build # New-GitlabPipeline |
| 93 | +go # Open-InBrowser |
221 | 94 | ``` |
222 | 95 |
|
223 | | -Opens latest successful pipeline in browser. |
224 | | - |
225 | | -### Resolve Variable |
| 96 | +### Pipeline to Browser |
226 | 97 |
|
227 | | -`Resolve-GitlabVariable` (aka `var`) checks a project or group for a variable. Walks up the group hierarchy until found, or no other nodes to check. |
228 | | -Automatically expands the value. |
229 | | - |
230 | | -Example |
231 | 98 | ```powershell |
232 | | -Get-GitlabProject | var APPLICATION_NAME |
233 | | -``` |
234 | | -```text |
235 | | -Your application |
| 99 | +Get-GitlabProject | Get-GitlabPipeline -Latest | Open-InBrowser |
236 | 100 | ``` |
237 | 101 |
|
238 | | - ### Get pipeline for latest deployement |
239 | | - |
240 | | - ```powershell |
241 | | - envs -Search prod | deploys -Latest -Select Pipeline [| go] |
242 | | - ``` |
| 102 | +## Documentation |
243 | 103 |
|
244 | | -### Deploy To Production |
| 104 | +📖 **[chris-peterson.github.io/pwsh-gitlab](https://chris-peterson.github.io/pwsh-gitlab)** |
245 | 105 |
|
246 | | -```powershell |
247 | | -~/src/your-project> pipelines -Branch 'main' -Status 'success' -Latest | |
248 | | - jobs -Stage deploy -Name prod | |
249 | | - Play-GitlabJob |
250 | | -``` |
| 106 | +- [Configuration Guide](https://chris-peterson.github.io/pwsh-gitlab/#/Config/) |
| 107 | +- [All Cmdlets by Category](https://chris-peterson.github.io/pwsh-gitlab) |
| 108 | +- [CI/CD: Pipelines & Jobs](https://chris-peterson.github.io/pwsh-gitlab/#/Pipelines/) |
| 109 | +- [Working with Merge Requests](https://chris-peterson.github.io/pwsh-gitlab/#/MergeRequests/) |
251 | 110 |
|
252 | | -### Get Pipeline Schedule |
253 | | - |
254 | | -```powershell |
255 | | -~/src/your-project> schedule |
| 111 | +## Contributing |
256 | 112 |
|
257 | | - ID Active Description Cron NextRunAt |
258 | | - -- ------ ----------- ---- --------- |
259 | | - 1948 True Weekly restore for database 0 3 * * 0 9/26/2021 10:04:00 AM |
260 | | - ``` |
| 113 | +Contributions welcome! Please see the [GitHub repository](https://github.com/chris-peterson/pwsh-gitlab) for issues and pull requests. |
261 | 114 |
|
262 | | -## References / Acknowledgements |
| 115 | +## References |
263 | 116 |
|
264 | | -* [PSGitLab](https://github.com/ngetchell/PSGitLab) (now archived) |
265 | | -* [python-gitlab CLI documentation](https://python-gitlab.readthedocs.io/en/stable) |
266 | | -* [GitLab API docs](https://docs.gitlab.com/ee/api/rest/index.html) |
267 | | -* [powershell-yaml](https://github.com/cloudbase/powershell-yaml) |
| 117 | +* [GitLab REST API Documentation](https://docs.gitlab.com/ee/api/rest/index.html) |
| 118 | +* [PowerShell Gallery Package](https://www.powershellgallery.com/packages/GitlabCli) |
0 commit comments