GitLab
In this section, you will learn how to configure your SCM integration with GitLab.
Integrating your
- Create Application;
- Create Infrastructure;
- Application of Plugins;
- Execution of Actions.
Requirements
1. Create a GitLab group and project
To integrate SCM with StackSpot, you must first create your organization's repository for pipelines. This way, when you define pipelines, you can activate them remotely via API by providing input data for each flow.
You can use an existing repository or create a new one.
If your organization doesn't have a Group or Project in GitLab, go to the following tabs to create them:
2. Generate a personal access token in GitLab
- Access your GitLab account and log in;
- In the left side menu, select your Avatar;
- Select Edit Profile;
- In the left side menu, select Access Tokens;
- Select Add new token;
- Enter the name and expiration date for the token. If you do not enter a due date, the due date is automatically set to 365 days after the current date;
- Select the following scopes:
write_repository
;create_runner
;api
.
Scopes may depend on the activities your company needs to perform. Therefore, select all the ones that are necessary for you. Access the full list of GitLab scopes.
- Select Create Personal Access Token.
- The generated code will be displayed temporarily, copy and save the generated code.
Configure pipelines automatically (recommended)
The following steps are done using the STK CLI. Check the installation instructions.
Step 1. Open your terminal and clone the Action repository:
git clone https://github.com/stack-spot/stackspot-workflows-action.git
The content is saved within your current folder.
Step 2. Access the cloned repository folder and execute the command below:
cd stackspot-workflows-action
stk run action .
Step 3. When the terminal asks what your SCM provider is, select the GitLab option.
Step 4. Answer the following questions:
- Personal Access Token: Enter the Personal Access Token generated in GitLab.
- Project name: Enter the name of your GitLab Project.
- Group Name: Enter the name of your GitLab Group.
- Is on premise? Enter Y (yes) to use On Premise GitLab service or N (no), to use cloud GitLab service.
- Gitlab api domain: Available when On Premise GitLab is selected. Enter the URL domain of your GitLab's organization name.
If the specified repository exists and the main
branch also exists in it, a Pull Request will be created for main
.
If the repository does not exist, the Action creates the repository and the main
branch.
The token user and the Personal Access Token itself must have permission to write to the organization's repository. If the repository does not exist, you must add permission to create repositories.
For more information, follow the GitLab documentation.
It is not the StackSpot Platform's Personal Access Token.
Done! The Action was executed.
If the configuration goes successfully, the next step is to integrate GitLab with your StackSpot account. If it is not possible to complete the form configuration automatically, follow the steps below to carry out the entire configuration manually:
Create the repository and pipelines manually
Step 1. In terminal STK CLI. Execute the commands:
mkdir <repo-name>
cd <repo-name>
Example:
mkdir repo-runner-actions
cd repo-runner-actions
Step 2. Create the ".gitlab-ci.yml"
file inside the previously generated folder with the following content:
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "push"
when: never
- when: always
image: ubuntu:latest
stages:
- run
variables:
workflow_name: ""
api_inputs: "{}"
default:
before_script:
- echo "Installing some necessary tools";
- apt-get -qq update;
- apt-get install -y jq curl git;
run:
stage: run
script:
- |
execution_id=$(echo $api_inputs | jq -cr '.execution_id')
secret_stk_login=$(echo $api_inputs | jq -cr '.secret_stk_login')
http_code=$(curl -s -o script.sh -w '%{http_code}' https://workflow-api.v1.stackspot.com/workflows/$execution_id --header "Authorization: Bearer $secret_stk_login";)
if [[ "$http_code" -ne "200" ]]; then
echo "------------------------------------------------------------------------------------------"
echo "---------------------------------------- Debug Starting ----------------------------------"
echo "------------------------------------------------------------------------------------------"
echo "HTTP_CODE:" $http_code
echo "RESPONSE_CONTENT:"
cat script.sh
exit $http_code
echo "------------------------------------------------------------------------------------------"
echo "---------------------------------------- Debug Ending ------------------------------------"
echo "------------------------------------------------------------------------------------------"
else
chmod +x script.sh
echo "------------------------------------------------------------------------------------------"
echo "---------------------------------------- Starting ----------------------------------------"
echo "------------------------------------------------------------------------------------------"
bash script.sh
echo "------------------------------------------------------------------------------------------"
echo "---------------------------------------- Ending ----------------------------------------"
echo "------------------------------------------------------------------------------------------"
fi
Step 3. Commit the changes using the commands below:
git init
git remote add origin https://gitlab.com/<gitlab-groupname>/<project-name>.git
git add .
git commit -m "Setup Runner"
git push
Example:
git init
git remote add origin https://gitlab.com/my-group/repo-runner-actions.git
git add .
git commit -m "Setup Runner"
git push
In some SCMs, the Project Name and Repository Name may mean the same thing. Check out how to identify these fields in the URL below:
https://gitlab.com/[GITLAB-GROUP]/[PROJECT-NAME]
Example:
https://gitlab.com/stack-spot/stackspot-workflows-action
Step 4. Access your GitLab project and follow the steps below:
- Access Settings and then CI/CD;
- Click on the Expand button of the Pipeline trigger tokens option;
- Fill in the Description field and then click the Create pipeline trigger token button.
Example:
If the configuration is successful, the next step is to integrate GitLab with your StackSpot account.
Integrate GitLab with StackSpot
The following steps are done on the StackSpot Portal.
Integrate cloud GitLab service with StackSpot
Configuring via GitLab PAT (Personal Access Token)
Step 1. Log in to StackSpot Portal. On the top left side of the screen, click on the selector button and select the Account option;
Step 2. In the left side menu, in the Settings section, click on ’SCM Integration’. Then click on the Configure SCM Integration’ button;
Step 3. In the Select a provider field, select GitLab;
Step 4. In Authentication Method, select the option PAT (Personal Access Token) and fill in the following fields:
- User: Your GitLab user name;
- Token: Use your Personal Access Token that you generated previously.
Step 5. In Workflow Configuration, choose how the organization wants to manage access to the SCM. To do so, turn the 'Will the organization manage access to the SCM via User PAT?' option on or off:
- Turn on: The user will manage access to GitLab via PAT (Personal Access Token).
- Turn off: The company will manage access to GitLab.
By turning on this button, your account members must configure their individual SCM Access.
Step 6. In the Workflow URL field, enter the repository URL created with the pipelines for StackSpot to identify where your workflow is configured. You will need the following information to fill in the URL:
https://gitlab.com/<group_name>/<repository_name>?project_id=<project_id>&trigger_id=<trigger_id>
To get the previous Workflow's URL information, access your GitLab account and follow the steps for each item.
- project id: Access the main page of your GitLab project. Click on the 'More actions' button, and you find the project id number.
- trigger id: Access your GitLab project and follow the steps below:
- Access Settings and then CI/CD;
- Click on the Pipeline trigger tokens title to expand the options;
- In the token's options, right-click the mouse on the 'Revoke trigger' button to display browser options.
- Click the 'Copy Link Address' option.
- Open a text editor you want and paste the Link Address you had copied.
You find the trigger id value number at the end of the URL.
Example:
# https://gitlab.com/<group_name>/<project_name>/-/triggers/<trigger_id>
https://gitlab.com/techwriters/documentation/-/triggers/1622887
Come back to StackSpot's Portal and finish the configuration:
Step 7. You will be redirected to the Review screen. Check your details and click 'Integrate with StackSpot'.
Integrate On Premise GitLab service with StackSpot
Configuring via GitLab PAT (Personal Access Token)
Step 1. Log in to StackSpot Portal, on the top left side of the screen, click on the selector button and select the **Account option **;
Step 2. In the left side menu, in the Settings section, click on ’SCM Integration’. Then click on the Configure SCM Integration’ button;
Step 3. In the Select a provider field, select GitLab;
Step 4. In Authentication Method, select the option PAT (Personal Access Token) and fill in the following fields:
- Url Provider: Your organization's GitLab URL provider. Enter the URL with the
https://
protocol. - User: Your GitLab user name;
- Token: Use your Personal Access Token that you generated previously.
Step 5. In Workflow Configuration, choose how the organization wants to manage access to the SCM, to do so, enable or disable the option 'Will the organization manage access to the SCM via User PAT? ':
- Enabled: The user will manage access to GitLab via PAT (Personal Access Token).
- Disabled: The company will manage access to GitLab.
By enabling this button, your account members must configure their individual SCM Access.
Step 6. In the Workflow URL field, enter the URL of the repository created with the pipelines for StackSpot to identify where your workflow is configured. You will need the following information to fill in the URL:
https://gitlab.com/<group_name>/<repository_name>?project_id=<project_id>&trigger_id=<trigger_id>
To get the previous Workflow's URL information, access your GitLab account and follow the steps for each item.
- project id: Access the main page of your GitLab project. Click on the 'More actions' button, and you find the project id number.
- trigger id: Access your GitLab project and follow the steps below:
- Access Settings and then CI/CD;
- Click on the Pipeline trigger tokens title to expand the options;
- In the token's options, right-click the mouse on the 'Revoke trigger' button to display browser options.
- Click on the 'Copy Link Address' option.
- Open a text editor you want and paste the Link Address you had copied.
You find the trigger id value number at the end of the URL.
Example:
# https://gitlab.com/<group_name>/<project_name>/-/triggers/<trigger_id>
https://gitlab.com/techwriters/documentation/-/triggers/1622887
Come back to StackSpot's Portal and finish the configuration:
Step 7. You will be redirected to the Review screen. Check your details and click 'Integrate with StackSpot'.
Done! Your configuration is complete.