Azure DevOps
In this section, you will learn how to configure your SCM integration with Azure DevOps.
You can integrate your
- Create Application;
- Create Infrastructure;
- Apply Plugins;
- Run Actions.
Requirements
1. Create a repository for the pipelines
To integrate your SCM with StackSpot, create a pipeline in your organization's repository. When they are defined, you can remotely request them, via API, informing your input data for each flow.
You can access Azure DevOps with a Microsoft or Github account, then create an organization and project:
In Azure DevOps,
- Your organization is equal to your username;
- Your project is equal to your repository name. To access them you must use the URL:
https://dev.azure.com/[ORGANIZATION-NAME]/[PROJECT-NAME]
Where:
- Organization name: Name you defined for your user.
- Project Name: Name you defined for your repository.
Example:
https://dev.azure.com/my-username/my-workflow-repo
You can also use an existing Project.
2. Generate Personal Access Token in Azure DevOps
In your organization, the user who can generate the token is within the group > 'Project Collection Administrators'. Confirm that you have this permission in 'Permissions' Azure section.
- Access your Azure account; Go to the address:
https://dev.azure.com/{Your_Organization}
and log in; - In the upper right menu, click on 'User Settings' and then click on 'Personal access tokens';
- Click the 'New Token' button and fill in the following fields:
-
Name: Enter a name for the token;
-
Organization: Select your organization;
-
Expiration (UTC): Select or set an expiration date for the token;
-
Scopes: Select from 'Full access' for full access or 'Custom defined' to choose permissions. If you choose 'Custom defined', check the following items:
- Auditing: Read Audit Log;
- Build: Read & execute;
- Code: Read & Write;
- Packaging: Read & Write;
- Pipeline Resources: Use & manage;
- Project and Team: Read, write & manage.
- Release: Read, write & execute;
- Services Connections: Read, query & manage.
- To finish, click on the 'Create' button. The token code will be displayed temporarily. Save the generated code.
Configure pipelines automatically (Recommended)
You will follow the next steps via STK CLI;
To create pipelines automatically, you need to fulfill all requirements:
Step 1. Open your terminal and clone the Action repository:
git clone https://github.com/stack-spot/stackspot-workflows-action.git
The content is inside your current folder.
Step 2. Access the cloned repository folder and run the command below:
cd stackspot-workflows-action
stk run action .
Step 3. The terminal asks which is your SCM provider. Select the Azure option.
Step 4. Answer the following questions:
- Personal Access Token: Enter the Personal Access Token previously generated in Azure DevOps;
- Project Name: Enter the name of the Project in Azure DevOps (repository you created to run StackSpot Workflows);
- Organization name: Enter the name you gave to the Organization in Azure DevOps;
- Repository Name: Enter the name of your repository that Action will create. This is the repository that will store your pipeline manifests.
-
If the specified repository exists and the
main
branch also exists in it, a Pull Request will be created formain
. If the repository does not exist, the Action creates the repository and themain
branch. -
When creating a Project, a repository with the same name is automatically created. However, the pipeline configuration is done at the Project level, but the manifest is in the Project repository. Therefore, filling in the name for your repository (Repository Name) is mandatory.
Done! The Action has successfully executed.
Check your repository (Project) in Azure DevOps. On the left side menu, click on 'Pipelines', and you will see the file "middle-flow" configured.
If the setup is successful, the next step is to integrate Azure DevOps with your StackSpot account. If it is not possible to complete the configuration automatically, follow the steps below to carry out the entire configuration manually:
Create repository and pipelines manually
You will follow the next steps via STK CLI; To create pipelines automatically, you need to fulfill all requirements:
Step 1. In the terminal STK CLI. Run the commands:
mkdir <repo-name>
cd <repo-name>
Example:
mkdir repo-runner-actions
cd repo-runner-actions
Step 2. Inside the folder you created, create the file "middle-flow.yml" with the following content:
trigger:
- none
name: ${{ parameters.correlation_id }}
parameters:
- name: correlation_id
displayName: Correlation id
type: string
- name: job_display_name
displayName: Job display name
type: string
- name: api_inputs
displayName: Json object with api data
type: string
- name: job_template
displayName: Job template
type: string
- name: resource_repositories_ref
displayName: Resource repository ref
type: string
pool:
name: default
jobs:
- job:
displayName: ${{ parameters.job_display_name }}
steps:
- bash: |
execution_id=$(echo '${{ parameters.api_inputs }}' | jq -cr '.execution_id')
export HTTP_ENABLE_FILE_DEBUG=false
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
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://<org>@dev.azure.com/<org>/<project_name>/_git/<repo_name>
git add .
git commit -m "Setup Runner"
git push
Example:
git init
git remote add origin https://stackspot-azure@dev.azure.com/stackspot-azure/stackspot/_git/stackspot
git add .
git commit -m "Setup Runner"
git push
Register the middle-flow file in the Azure DevOps pipeline
After creating the repository and pipelines from the previous steps, you must register the pipeline: middle-flow
. To do so, access your organization on Azure DevOps and follow the steps below:
Step 1. Enter the project where the repository used in the previous step is located.
Step 2. In the left side menu, click on 'Pipelines', then in the upper right corner click on the button 'New pipeline';
Step 3. Select the option 'Azure Repos Git';
Step 4. Select the previously created repository to be the repository that will create the Pipeline;
Step 5. Click on 'Existing Azure Pipelines YAML file', then on the option 'Path' select the file /middle-flow.yml
;
Step 6. On the Review your YAML pipeline screen, click the 'Variables' button, then 'New variable';
Step 7. You must register two variables, the first with the following values:
- Name: Enter the exact name
secret_cli_login
; - Value: --- (Do not fill in any value);
Check both checkboxes:
- 'Keep this value secret';
- 'Let users override this value when running this pipeline'. Click the 'OK' button to finish.
Step 8. On the same screen, repeat the process. Click the 'Variables' button, then 'New variable':
- Name: Enter the exact name
secret_git
; - Value: --- (Do not fill in any value);
Check both checkboxes:
- 'Keep this value secret';
- 'Let users override this value when running this pipeline'.
Click on the 'OK' button and then click 'Save' button to finish.
Step 8. The pipeline is created with a random name, you must rename the pipeline to the name: 'middle-flow'. To do so, access the option Pipelines in the left side menu and then the option 'all';
Step 9. Locate the generated pipeline, and click on the 'more options' button and then on 'Rename/move pipeline';
Step 10. In the 'Name' field type 'middle-flow' then click the 'Save' button.
Now you need the project's URL to use in the following integration process.
Integrate Azure DevOps with StackSpot
You will follow the steps below on StackSpot Platform.
Configure via Azure DevOps PAT (Personal Access Token)
Step 1. Log in to the StackSpot Platform. On the upper left side of the screen, click on the selector button and select the Account option;
Step 2. On 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 Azure DevOps;
Step 4. Under Authentication Method, select the PAT (Personal Access Token) option and fill in the following fields:
- User: The name of your Azure DevOps user;
- Token: Use your Azure DevOps Personal Access Token that you previously generated.
Step 5. In Workflow Configuration, choose how the organization wants to manage access to the SCM, for that, enable or disable the option 'Will the organization manage access to the SCM via User PAT? ':
- Enabled: User will manage access to Azure DevOps via PAT (Personal Access Token).
- Disabled: The company will manage access to Azure DevOps.
By enabling 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 configuration. For example https://dev.azure.com/myazure-user/scm-azure-pipes
.
Step 7. You will be redirected to the Review screen. Check your data and click on 'Integrate with StackSpot'.
Done! Your configuration is complete.