gitlab-pipeline-automator 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ENV_SETUP.md +235 -0
- package/LICENSE +21 -0
- package/README.md +432 -0
- package/package.json +49 -0
- package/pipeline_automation.js +731 -0
- package/postinstall.js +66 -0
package/ENV_SETUP.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# Environment Variables Setup Guide
|
|
2
|
+
|
|
3
|
+
This guide shows you how to set up the `SCRIPTS_PATH` environment variable for the GitLab Pipeline Automator.
|
|
4
|
+
|
|
5
|
+
## Quick Setup
|
|
6
|
+
|
|
7
|
+
### macOS / Linux
|
|
8
|
+
|
|
9
|
+
**Permanent setup (recommended):**
|
|
10
|
+
```bash
|
|
11
|
+
# Add to ~/.zshrc (macOS) or ~/.bashrc (Linux)
|
|
12
|
+
echo 'export SCRIPTS_PATH="/path/to/your/scripts"' >> ~/.zshrc
|
|
13
|
+
source ~/.zshrc
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Temporary (current session only):**
|
|
17
|
+
```bash
|
|
18
|
+
export SCRIPTS_PATH="/path/to/scripts"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Windows (PowerShell)
|
|
22
|
+
|
|
23
|
+
**Permanent setup (recommended):**
|
|
24
|
+
```powershell
|
|
25
|
+
[System.Environment]::SetEnvironmentVariable("SCRIPTS_PATH", "C:\path\to\your\scripts", "User")
|
|
26
|
+
```
|
|
27
|
+
Restart PowerShell after running this command.
|
|
28
|
+
|
|
29
|
+
**Temporary (current session only):**
|
|
30
|
+
```powershell
|
|
31
|
+
$env:SCRIPTS_PATH="C:\path\to\scripts"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Step-by-Step Instructions
|
|
35
|
+
|
|
36
|
+
### macOS
|
|
37
|
+
|
|
38
|
+
1. **Open Terminal**
|
|
39
|
+
|
|
40
|
+
2. **Edit your Zsh configuration:**
|
|
41
|
+
```bash
|
|
42
|
+
nano ~/.zshrc
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
3. **Add your environment variables:**
|
|
46
|
+
```bash
|
|
47
|
+
export SCRIPTS_PATH="/Users/yourusername/path/to/scripts"
|
|
48
|
+
export GITLAB_BASE_URL="https://devops.nhc.sa"
|
|
49
|
+
export GITLAB_PROJECT_PATH="/ejar3/devs/ejar3-run-script-tool"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
4. **Save and exit:**
|
|
53
|
+
- Press `Ctrl + X`
|
|
54
|
+
- Press `Y` to confirm
|
|
55
|
+
- Press `Enter` to save
|
|
56
|
+
|
|
57
|
+
5. **Reload your configuration:**
|
|
58
|
+
```bash
|
|
59
|
+
source ~/.zshrc
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
6. **Verify it's set:**
|
|
63
|
+
```bash
|
|
64
|
+
echo $SCRIPTS_PATH
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Linux
|
|
68
|
+
|
|
69
|
+
1. **Open Terminal**
|
|
70
|
+
|
|
71
|
+
2. **Edit your Bash configuration:**
|
|
72
|
+
```bash
|
|
73
|
+
nano ~/.bashrc
|
|
74
|
+
# or
|
|
75
|
+
nano ~/.bash_profile
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
3. **Add your SCRIPTS_PATH:**
|
|
79
|
+
```bash
|
|
80
|
+
export SCRIPTS_PATH="/home/yourusername/path/to/scripts"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
4. **Save and reload:**
|
|
84
|
+
```bash
|
|
85
|
+
source ~/.bashrc
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
5. **Verify:**
|
|
89
|
+
```bash
|
|
90
|
+
echo $SCRIPTS_PATH
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Windows (PowerShell)
|
|
94
|
+
|
|
95
|
+
#### Method 1: PowerShell Profile (Recommended)
|
|
96
|
+
|
|
97
|
+
1. **Open PowerShell**
|
|
98
|
+
|
|
99
|
+
2. **Check if profile exists:**
|
|
100
|
+
```powershell
|
|
101
|
+
Test-Path $PROFILE
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
3. **Create/edit profile:**
|
|
105
|
+
```powershell
|
|
106
|
+
if (!(Test-Path $PROFILE)) {
|
|
107
|
+
New-Item -Path $PROFILE -Type File -Force
|
|
108
|
+
}
|
|
109
|
+
notepad $PROFILE
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
4. **Add your SCRIPTS_PATH:**
|
|
113
|
+
```powershell
|
|
114
|
+
$env:SCRIPTS_PATH = "C:\Users\YourUsername\path\to\scripts"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
5. **Save and restart PowerShell**
|
|
118
|
+
|
|
119
|
+
#### Method 2: System Environment Variables (GUI)
|
|
120
|
+
|
|
121
|
+
1. **Open System Properties:**
|
|
122
|
+
- Press `Win + R`
|
|
123
|
+
- Type `sysdm.cpl` and press Enter
|
|
124
|
+
- Click "Advanced" tab
|
|
125
|
+
- Click "Environment Variables"
|
|
126
|
+
|
|
127
|
+
2. **Add User Variable:**
|
|
128
|
+
- Under "User variables", click "New"
|
|
129
|
+
- Variable name: `SCRIPTS_PATH`
|
|
130
|
+
- Variable value: `C:\Users\YourUsername\path\to\scripts`
|
|
131
|
+
- Click "OK"
|
|
132
|
+
|
|
133
|
+
3. **Repeat for other variables**
|
|
134
|
+
|
|
135
|
+
4. **Restart your terminal/command prompt**
|
|
136
|
+
|
|
137
|
+
#### Method 3: Command Line (Permanent)
|
|
138
|
+
|
|
139
|
+
1. **Open PowerShell as Administrator**
|
|
140
|
+
|
|
141
|
+
2. **Set SCRIPTS_PATH:**
|
|
142
|
+
```powershell
|
|
143
|
+
[System.Environment]::SetEnvironmentVariable("SCRIPTS_PATH", "C:\path\to\scripts", "User")
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
3. **Restart PowerShell**
|
|
147
|
+
|
|
148
|
+
## Required Environment Variable
|
|
149
|
+
|
|
150
|
+
| Variable | Description | Example | Required |
|
|
151
|
+
|----------|-------------|---------|----------|
|
|
152
|
+
| `SCRIPTS_PATH` | Path to directory containing Ruby scripts | `/Users/username/scripts` | ✅ **Yes** |
|
|
153
|
+
|
|
154
|
+
## Optional Environment Variables
|
|
155
|
+
|
|
156
|
+
These have defaults and are optional:
|
|
157
|
+
|
|
158
|
+
| Variable | Description | Default Value |
|
|
159
|
+
|----------|-------------|---------------|
|
|
160
|
+
| `GITLAB_BASE_URL` | GitLab instance base URL | `https://devops.nhc.sa` |
|
|
161
|
+
| `GITLAB_PROJECT_PATH` | GitLab project path | `/ejar3/devs/ejar3-run-script-tool` |
|
|
162
|
+
| `CDP_PORT` | Chrome DevTools Protocol port | `9222` |
|
|
163
|
+
| `CHROME_USER_DATA_DIR` | Chrome user data directory | Auto-created in `~/.config/gitlab-pipeline-automator/chrome-profile` |
|
|
164
|
+
| `CHROME_PROFILE_DIR` | Chrome profile directory name | `Default` |
|
|
165
|
+
|
|
166
|
+
## Verification
|
|
167
|
+
|
|
168
|
+
After setting up, verify your environment variables:
|
|
169
|
+
|
|
170
|
+
**macOS / Linux:**
|
|
171
|
+
```bash
|
|
172
|
+
echo $SCRIPTS_PATH
|
|
173
|
+
echo $GITLAB_BASE_URL
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Windows (PowerShell):**
|
|
177
|
+
```powershell
|
|
178
|
+
echo $env:SCRIPTS_PATH
|
|
179
|
+
echo $env:GITLAB_BASE_URL
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Windows (Command Prompt):**
|
|
183
|
+
```cmd
|
|
184
|
+
echo %SCRIPTS_PATH%
|
|
185
|
+
echo %GITLAB_BASE_URL%
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Usage After Setup
|
|
189
|
+
|
|
190
|
+
Once environment variables are set, you can use the tool without specifying paths:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
# Before (without env vars):
|
|
194
|
+
gitlab-pipeline-automator \
|
|
195
|
+
--scripts-path "/path/to/scripts" \
|
|
196
|
+
-t "ticket" -s "script" -e "service"
|
|
197
|
+
|
|
198
|
+
# After (with env vars):
|
|
199
|
+
gitlab-pipeline-automator -t "ticket" -s "script" -e "service"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Troubleshooting
|
|
203
|
+
|
|
204
|
+
### Variable Not Found
|
|
205
|
+
|
|
206
|
+
**Problem:** `echo $SCRIPTS_PATH` returns empty
|
|
207
|
+
|
|
208
|
+
**Solution:**
|
|
209
|
+
1. Make sure you saved the configuration file
|
|
210
|
+
2. Reload your shell: `source ~/.zshrc` (or `~/.bashrc`)
|
|
211
|
+
3. Restart your terminal
|
|
212
|
+
4. Check for typos in variable names
|
|
213
|
+
|
|
214
|
+
### Changes Not Persisting
|
|
215
|
+
|
|
216
|
+
**Problem:** Variables work in current session but disappear after closing terminal
|
|
217
|
+
|
|
218
|
+
**Solution:**
|
|
219
|
+
- Make sure you added them to the correct configuration file:
|
|
220
|
+
- macOS: `~/.zshrc`
|
|
221
|
+
- Linux: `~/.bashrc` or `~/.bash_profile`
|
|
222
|
+
- Windows: PowerShell profile or System Environment Variables
|
|
223
|
+
|
|
224
|
+
### Path Issues on Windows
|
|
225
|
+
|
|
226
|
+
**Problem:** Path not working on Windows
|
|
227
|
+
|
|
228
|
+
**Solution:**
|
|
229
|
+
- Use forward slashes or escaped backslashes:
|
|
230
|
+
```powershell
|
|
231
|
+
# Good
|
|
232
|
+
$env:SCRIPTS_PATH = "C:/Users/username/scripts"
|
|
233
|
+
# or
|
|
234
|
+
$env:SCRIPTS_PATH = "C:\Users\username\scripts"
|
|
235
|
+
```
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Mahad Asif
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
# GitLab Pipeline Automator
|
|
2
|
+
|
|
3
|
+
Automation script for GitLab pipeline management. This tool automatically creates, approves, and monitors GitLab pipelines using browser automation.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🚀 **Automatic Chrome Launch**: Automatically launches Chrome with remote debugging when needed
|
|
8
|
+
- 🔄 **Cross-platform**: Works on macOS, Windows, and Linux
|
|
9
|
+
- ⚙️ **Configurable**: Supports environment variables and CLI options
|
|
10
|
+
- 📦 **NPM Package**: Can be installed globally or used as a module
|
|
11
|
+
- 🎯 **Smart Retry Logic**: Built-in retry mechanisms for reliability
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### As a Global NPM Package
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g gitlab-pipeline-automator
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
After installation, you can use the `gitlab-pipeline-automator` command from anywhere.
|
|
22
|
+
|
|
23
|
+
> ⚠️ **Important:** After installation, you'll see setup instructions. Make sure to:
|
|
24
|
+
> 1. Set the `SCRIPTS_PATH` environment variable (see [Environment Variables](#environment-variables) below)
|
|
25
|
+
> 2. Install Playwright browsers: `npx playwright install chromium firefox`
|
|
26
|
+
|
|
27
|
+
### As a Local Package
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Then run with:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm start -- -t <ticket> -s <script> -e <service>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Install Playwright Browsers
|
|
40
|
+
|
|
41
|
+
After installation, you need to install Playwright browsers:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx playwright install chromium firefox
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Command Line Interface
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
gitlab-pipeline-automator \
|
|
53
|
+
-t "ticket-description" \
|
|
54
|
+
-s "script-name" \
|
|
55
|
+
-e "ejar-service-name" \
|
|
56
|
+
-b "production"
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Required Arguments
|
|
60
|
+
|
|
61
|
+
- `-t, --ticket <ticket>`: Ticket description
|
|
62
|
+
- `-s, --script <script>`: Ruby script filename (without .rb extension)
|
|
63
|
+
- `-e, --ejar-service <service>`: Ejar3 service name
|
|
64
|
+
|
|
65
|
+
#### Optional Arguments
|
|
66
|
+
|
|
67
|
+
- `-b, --branch <branch>`: Git branch to use (default: "production")
|
|
68
|
+
- `--scripts-path <path>`: Path to scripts directory (overrides `SCRIPTS_PATH` env var)
|
|
69
|
+
- `--gitlab-url <url>`: GitLab base URL (overrides `GITLAB_BASE_URL` env var)
|
|
70
|
+
- `--project-path <path>`: GitLab project path (overrides `GITLAB_PROJECT_PATH` env var)
|
|
71
|
+
- `--cdp-port <port>`: Chrome DevTools Protocol port (default: 9222)
|
|
72
|
+
- `--chrome-user-data-dir <path>`: Chrome user data directory for saved credentials/login (overrides `CHROME_USER_DATA_DIR` env var)
|
|
73
|
+
- `--chrome-profile-dir <name>`: Chrome profile directory name (default: "Default") (overrides `CHROME_PROFILE_DIR` env var)
|
|
74
|
+
|
|
75
|
+
### Environment Variables
|
|
76
|
+
|
|
77
|
+
> 📖 **First-time setup?** See [ENV_SETUP.md](./ENV_SETUP.md) for detailed step-by-step instructions.
|
|
78
|
+
|
|
79
|
+
The main environment variable you need to set is `SCRIPTS_PATH` - the path to your Ruby scripts directory. This allows you to run the tool without specifying `--scripts-path` every time.
|
|
80
|
+
|
|
81
|
+
#### Setting Up SCRIPTS_PATH
|
|
82
|
+
|
|
83
|
+
**macOS / Linux:**
|
|
84
|
+
|
|
85
|
+
Add to your `~/.zshrc` (or `~/.bashrc` on Linux):
|
|
86
|
+
```bash
|
|
87
|
+
export SCRIPTS_PATH="/path/to/your/scripts"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Then reload:
|
|
91
|
+
```bash
|
|
92
|
+
source ~/.zshrc # or source ~/.bashrc
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Windows (PowerShell):**
|
|
96
|
+
|
|
97
|
+
Open PowerShell and run:
|
|
98
|
+
```powershell
|
|
99
|
+
[System.Environment]::SetEnvironmentVariable("SCRIPTS_PATH", "C:\path\to\your\scripts", "User")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Restart PowerShell for changes to take effect.
|
|
103
|
+
|
|
104
|
+
**Windows (GUI Method):**
|
|
105
|
+
|
|
106
|
+
1. Press `Win + R`, type `sysdm.cpl`, press Enter
|
|
107
|
+
2. Click "Environment Variables"
|
|
108
|
+
3. Under "User variables", click "New"
|
|
109
|
+
4. Variable name: `SCRIPTS_PATH`
|
|
110
|
+
5. Variable value: `C:\path\to\your\scripts`
|
|
111
|
+
6. Click OK and restart your terminal
|
|
112
|
+
|
|
113
|
+
> 📖 **For detailed setup instructions, see [ENV_SETUP.md](./ENV_SETUP.md)**
|
|
114
|
+
|
|
115
|
+
#### Other Optional Environment Variables
|
|
116
|
+
|
|
117
|
+
You can also set these if needed (they have defaults):
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
export GITLAB_BASE_URL="https://your-gitlab-instance.com" # Default: https://devops.nhc.sa
|
|
121
|
+
export GITLAB_PROJECT_PATH="/group/project" # Default: /ejar3/devs/ejar3-run-script-tool
|
|
122
|
+
export CDP_PORT=9222 # Default: 9222
|
|
123
|
+
export CHROME_USER_DATA_DIR="/path/to/chrome/profile" # Optional
|
|
124
|
+
export CHROME_PROFILE_DIR="Profile 1" # Default: Default
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Setting Up Environment Variables Permanently
|
|
128
|
+
|
|
129
|
+
To make environment variables persist across terminal sessions, add them to your shell configuration file:
|
|
130
|
+
|
|
131
|
+
##### macOS / Linux (Bash)
|
|
132
|
+
|
|
133
|
+
1. Open your shell configuration file:
|
|
134
|
+
```bash
|
|
135
|
+
# For Bash
|
|
136
|
+
nano ~/.bash_profile
|
|
137
|
+
# or
|
|
138
|
+
nano ~/.bashrc
|
|
139
|
+
|
|
140
|
+
# For Zsh (default on macOS)
|
|
141
|
+
nano ~/.zshrc
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
2. Add the environment variables:
|
|
145
|
+
```bash
|
|
146
|
+
export SCRIPTS_PATH="/path/to/your/scripts"
|
|
147
|
+
export GITLAB_BASE_URL="https://devops.nhc.sa"
|
|
148
|
+
export GITLAB_PROJECT_PATH="/ejar3/devs/ejar3-run-script-tool"
|
|
149
|
+
export CDP_PORT=9222
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
3. Save and reload:
|
|
153
|
+
```bash
|
|
154
|
+
# Reload the configuration
|
|
155
|
+
source ~/.zshrc # or ~/.bashrc
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
##### macOS / Linux (Zsh)
|
|
159
|
+
|
|
160
|
+
1. Edit `~/.zshrc`:
|
|
161
|
+
```bash
|
|
162
|
+
nano ~/.zshrc
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
2. Add the variables:
|
|
166
|
+
```bash
|
|
167
|
+
export SCRIPTS_PATH="/path/to/your/scripts"
|
|
168
|
+
export GITLAB_BASE_URL="https://devops.nhc.sa"
|
|
169
|
+
export GITLAB_PROJECT_PATH="/ejar3/devs/ejar3-run-script-tool"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
3. Reload:
|
|
173
|
+
```bash
|
|
174
|
+
source ~/.zshrc
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
##### Windows (PowerShell)
|
|
178
|
+
|
|
179
|
+
1. Open PowerShell as Administrator
|
|
180
|
+
|
|
181
|
+
2. Set user-level environment variable:
|
|
182
|
+
```powershell
|
|
183
|
+
[System.Environment]::SetEnvironmentVariable("SCRIPTS_PATH", "C:\path\to\scripts", "User")
|
|
184
|
+
[System.Environment]::SetEnvironmentVariable("GITLAB_BASE_URL", "https://devops.nhc.sa", "User")
|
|
185
|
+
[System.Environment]::SetEnvironmentVariable("GITLAB_PROJECT_PATH", "/ejar3/devs/ejar3-run-script-tool", "User")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
3. Restart PowerShell for changes to take effect
|
|
189
|
+
|
|
190
|
+
**Alternative (PowerShell Profile):**
|
|
191
|
+
|
|
192
|
+
1. Check if profile exists:
|
|
193
|
+
```powershell
|
|
194
|
+
Test-Path $PROFILE
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
2. Create/edit profile:
|
|
198
|
+
```powershell
|
|
199
|
+
notepad $PROFILE
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
3. Add variables:
|
|
203
|
+
```powershell
|
|
204
|
+
$env:SCRIPTS_PATH = "C:\path\to\scripts"
|
|
205
|
+
$env:GITLAB_BASE_URL = "https://devops.nhc.sa"
|
|
206
|
+
$env:GITLAB_PROJECT_PATH = "/ejar3/devs/ejar3-run-script-tool"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
##### Windows (GUI Method)
|
|
210
|
+
|
|
211
|
+
1. Open System Properties:
|
|
212
|
+
- Press `Win + R`, type `sysdm.cpl`, press Enter
|
|
213
|
+
- Or: Right-click "This PC" → Properties → Advanced system settings
|
|
214
|
+
|
|
215
|
+
2. Click "Environment Variables"
|
|
216
|
+
|
|
217
|
+
3. Under "User variables", click "New"
|
|
218
|
+
|
|
219
|
+
4. Add each variable:
|
|
220
|
+
- Variable name: `SCRIPTS_PATH`
|
|
221
|
+
- Variable value: `C:\path\to\scripts`
|
|
222
|
+
- Click OK
|
|
223
|
+
|
|
224
|
+
5. Repeat for other variables
|
|
225
|
+
|
|
226
|
+
6. Restart your terminal/command prompt
|
|
227
|
+
|
|
228
|
+
#### Verifying Environment Variables
|
|
229
|
+
|
|
230
|
+
Check if your environment variables are set correctly:
|
|
231
|
+
|
|
232
|
+
**macOS / Linux:**
|
|
233
|
+
```bash
|
|
234
|
+
echo $SCRIPTS_PATH
|
|
235
|
+
echo $GITLAB_BASE_URL
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Windows (PowerShell):**
|
|
239
|
+
```powershell
|
|
240
|
+
echo $env:SCRIPTS_PATH
|
|
241
|
+
echo $env:GITLAB_BASE_URL
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Windows (Command Prompt):**
|
|
245
|
+
```cmd
|
|
246
|
+
echo %SCRIPTS_PATH%
|
|
247
|
+
echo %GITLAB_BASE_URL%
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### Example: Setting Up SCRIPTS_PATH
|
|
251
|
+
|
|
252
|
+
If your Ruby scripts are located at `/Users/username/scripts`:
|
|
253
|
+
|
|
254
|
+
**macOS:**
|
|
255
|
+
```bash
|
|
256
|
+
# Add to ~/.zshrc
|
|
257
|
+
export SCRIPTS_PATH="/Users/username/scripts"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Windows:**
|
|
261
|
+
```powershell
|
|
262
|
+
# PowerShell
|
|
263
|
+
[System.Environment]::SetEnvironmentVariable("SCRIPTS_PATH", "C:\Users\username\scripts", "User")
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
After setting up, you can run the tool without specifying `--scripts-path`:
|
|
267
|
+
```bash
|
|
268
|
+
gitlab-pipeline-automator -t "ticket" -s "script" -e "service"
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Using as a Module
|
|
272
|
+
|
|
273
|
+
```javascript
|
|
274
|
+
import GitLabPipelineAutomator from 'gitlab-pipeline-automator';
|
|
275
|
+
|
|
276
|
+
const automator = new GitLabPipelineAutomator({
|
|
277
|
+
scriptsPath: '/path/to/scripts',
|
|
278
|
+
gitlabBaseUrl: 'https://devops.nhc.sa',
|
|
279
|
+
gitlabProjectPath: '/ejar3/devs/ejar3-run-script-tool',
|
|
280
|
+
cdpPort: 9222,
|
|
281
|
+
chromeUserDataDir: '/path/to/chrome/profile', // Optional: for saved credentials
|
|
282
|
+
chromeProfileDir: 'Default' // Optional: profile name
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// Connect to Chrome (will auto-launch if needed)
|
|
286
|
+
await automator.connectToExistingChrome();
|
|
287
|
+
|
|
288
|
+
// Navigate and create pipeline
|
|
289
|
+
await automator.navigateToGitlabPipeline();
|
|
290
|
+
await automator.selectBranch('production');
|
|
291
|
+
const script = await automator.readScript('my-script');
|
|
292
|
+
await automator.processCiVariables('ticket-desc', script, 'service-name');
|
|
293
|
+
await automator.waitForPipelinePage();
|
|
294
|
+
|
|
295
|
+
// Approve and run
|
|
296
|
+
await automator.approvePipelineStage();
|
|
297
|
+
await automator.runPipelineStage();
|
|
298
|
+
|
|
299
|
+
// Cleanup
|
|
300
|
+
await automator.close();
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## How It Works
|
|
304
|
+
|
|
305
|
+
1. **Browser Connection**: The tool first attempts to connect to an existing Chrome instance with remote debugging enabled. If not found, it automatically launches Chrome with the required flags.
|
|
306
|
+
|
|
307
|
+
2. **Pipeline Creation**: Navigates to the GitLab pipeline creation page, selects the specified branch, and fills in CI variables (ticket description, service, and script content).
|
|
308
|
+
|
|
309
|
+
3. **Pipeline Approval**: Waits for the approval stage and automatically clicks the approve button when available.
|
|
310
|
+
|
|
311
|
+
4. **Pipeline Execution**: Monitors the pipeline execution until completion, reporting success or failure.
|
|
312
|
+
|
|
313
|
+
## Configuration
|
|
314
|
+
|
|
315
|
+
### Default Configuration
|
|
316
|
+
|
|
317
|
+
- **Scripts Path**: `/Users/mahadasif/Desktop/wareef-scripts` (macOS default)
|
|
318
|
+
- **GitLab URL**: `https://devops.nhc.sa`
|
|
319
|
+
- **Project Path**: `/ejar3/devs/ejar3-run-script-tool`
|
|
320
|
+
- **CDP Port**: `9222`
|
|
321
|
+
|
|
322
|
+
### Chrome Path Detection
|
|
323
|
+
|
|
324
|
+
The tool automatically detects Chrome installation paths:
|
|
325
|
+
|
|
326
|
+
- **macOS**: `/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`
|
|
327
|
+
- **Windows**: Checks common installation paths
|
|
328
|
+
- **Linux**: Checks `/usr/bin/google-chrome`, `/usr/bin/chromium`, etc.
|
|
329
|
+
|
|
330
|
+
### Automatic Login with Chrome Profiles
|
|
331
|
+
|
|
332
|
+
The tool supports using Chrome user profiles to automatically log in to GitLab using saved credentials. **By default, the tool automatically creates a persistent Chrome profile** to save your login credentials.
|
|
333
|
+
|
|
334
|
+
#### Automatic Profile Creation (Default Behavior)
|
|
335
|
+
|
|
336
|
+
When you run the tool for the first time **without** specifying `--chrome-user-data-dir`, it automatically creates a dedicated Chrome profile directory:
|
|
337
|
+
|
|
338
|
+
**Default Chrome Profile Locations:**
|
|
339
|
+
|
|
340
|
+
- **macOS**: `~/.config/gitlab-pipeline-automator/chrome-profile`
|
|
341
|
+
- Full path example: `/Users/username/.config/gitlab-pipeline-automator/chrome-profile`
|
|
342
|
+
|
|
343
|
+
- **Windows**: `%APPDATA%\gitlab-pipeline-automator\chrome-profile`
|
|
344
|
+
- Full path example: `C:\Users\username\AppData\Roaming\gitlab-pipeline-automator\chrome-profile`
|
|
345
|
+
- Or: `%LOCALAPPDATA%\gitlab-pipeline-automator\chrome-profile` if APPDATA is not available
|
|
346
|
+
|
|
347
|
+
- **Linux**: `~/.config/gitlab-pipeline-automator/chrome-profile`
|
|
348
|
+
- Full path example: `/home/username/.config/gitlab-pipeline-automator/chrome-profile`
|
|
349
|
+
|
|
350
|
+
**Note:** The exact location is displayed in the console output when the tool runs. The profile persists across runs, so once you log in to GitLab the first time, you'll stay logged in for future runs.
|
|
351
|
+
|
|
352
|
+
#### Option 1: Use Default Chrome Profile
|
|
353
|
+
|
|
354
|
+
If you're already logged into GitLab in your regular Chrome browser, the tool will automatically use those credentials when connecting to an existing Chrome instance.
|
|
355
|
+
|
|
356
|
+
#### Option 2: Use Custom Chrome Profile
|
|
357
|
+
|
|
358
|
+
You can specify a custom Chrome user data directory to use saved credentials:
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
# Using CLI
|
|
362
|
+
gitlab-pipeline-automator \
|
|
363
|
+
--chrome-user-data-dir "/Users/username/Library/Application Support/Google/Chrome" \
|
|
364
|
+
--chrome-profile-dir "Profile 1" \
|
|
365
|
+
-t "ticket" -s "script" -e "service"
|
|
366
|
+
|
|
367
|
+
# Using environment variables
|
|
368
|
+
export CHROME_USER_DATA_DIR="/Users/username/Library/Application Support/Google/Chrome"
|
|
369
|
+
export CHROME_PROFILE_DIR="Profile 1"
|
|
370
|
+
gitlab-pipeline-automator -t "ticket" -s "script" -e "service"
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
#### Finding Your Chrome Profile Path
|
|
374
|
+
|
|
375
|
+
**macOS:**
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
~/Library/Application Support/Google/Chrome
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
**Windows:**
|
|
382
|
+
|
|
383
|
+
```bash
|
|
384
|
+
%LOCALAPPDATA%\Google\Chrome\User Data
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
**Linux:**
|
|
388
|
+
|
|
389
|
+
```bash
|
|
390
|
+
~/.config/google-chrome
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
#### Profile Directory Names
|
|
394
|
+
|
|
395
|
+
- `Default` - The default profile (most common)
|
|
396
|
+
- `Profile 1`, `Profile 2`, etc. - Additional profiles if you have multiple Chrome profiles
|
|
397
|
+
|
|
398
|
+
**Note:**
|
|
399
|
+
- When using a custom profile, Chrome will use saved cookies and session data, so you'll be automatically logged in to GitLab if you've logged in before in that profile.
|
|
400
|
+
- **If you don't specify `--chrome-user-data-dir`, the tool automatically creates a persistent profile** in `~/.config/gitlab-pipeline-automator/chrome-profile` (or equivalent on Windows/Linux) on first run. This profile will persist your login credentials for future runs, so you only need to log in once.
|
|
401
|
+
|
|
402
|
+
## Requirements
|
|
403
|
+
|
|
404
|
+
- Node.js >= 14.0.0
|
|
405
|
+
- Google Chrome or Chromium installed
|
|
406
|
+
- Playwright browsers installed (`npx playwright install`)
|
|
407
|
+
|
|
408
|
+
## Troubleshooting
|
|
409
|
+
|
|
410
|
+
### Chrome Not Found
|
|
411
|
+
|
|
412
|
+
If Chrome is not automatically detected, ensure it's installed in a standard location, or set the path manually in the code.
|
|
413
|
+
|
|
414
|
+
### Connection Issues
|
|
415
|
+
|
|
416
|
+
If you encounter connection issues:
|
|
417
|
+
|
|
418
|
+
1. Ensure no other process is using port 9222
|
|
419
|
+
2. Check that Chrome is not already running with remote debugging on a different port
|
|
420
|
+
3. Try closing all Chrome instances and let the tool launch it automatically
|
|
421
|
+
|
|
422
|
+
### Pipeline Not Found
|
|
423
|
+
|
|
424
|
+
Ensure your GitLab project path and base URL are correctly configured. The tool expects specific GitLab UI elements - if your GitLab instance uses a different UI, you may need to adjust the selectors in the code.
|
|
425
|
+
|
|
426
|
+
## License
|
|
427
|
+
|
|
428
|
+
ISC
|
|
429
|
+
|
|
430
|
+
## Contributing
|
|
431
|
+
|
|
432
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|