|
|
|
parameters: |
|
# - name: deployDev |
|
# displayName: Deploy to Dev? |
|
# type: string |
|
# default: No |
|
# values: |
|
# - No |
|
# - Yes |
|
- name: deployProd |
|
displayName: Deploy to Production? (Approval Required) |
|
type: string |
|
default: No |
|
values: |
|
- No |
|
- Yes |
|
|
|
trigger: |
|
branches: |
|
include: |
|
- master |
|
- hotfix/* |
|
|
|
pr: none |
|
|
|
pool: |
|
vmImage: ubuntu-latest |
|
|
|
resources: |
|
repositories: |
|
- repository: 'PSCorePipelineTemplates' |
|
type: github |
|
name: technekes/ps-core-pipeline-templates |
|
endpoint: technekes |
|
ref: 'refs/heads/version/1.0' |
|
|
|
variables: |
|
- name: encryptionKey |
|
value: $(KEY) |
|
- name: secretLocation |
|
value: '.azure-pipelines/secrets.encrypted' |
|
- name: buildArgs |
|
value: $(BUILD_ARGS) |
|
- name: dockerCredentialLocation |
|
value: '.azure-pipelines/dockercfg.encrypted' |
|
- name: dockerComposeLocation |
|
value: '.azure-pipelines/docker-compose-ci.yml' |
|
- name: dockerComposeFileName |
|
value: 'docker-compose.yml' |
|
- name: buildRepositoryName |
|
value: $(Build.Repository.Name) |
|
- name: buildSourceVersion |
|
value: $(Build.SourceVersion) |
|
- name: regionName |
|
value: 'us-east-1' |
|
- name: imageSourcePush |
|
value: 'imagename' |
|
- name: imageSourcePull |
|
value: 'imagetag' |
|
- name: azureApiKey |
|
value: $(ADO_API_KEY) |
|
- name: herokuApiToken |
|
value: $(HEROKU_API_TOKEN) |
|
|
|
# IF COPYING THIS INTO A NEW API - CHANGE THE VALUES BELOW APPROPRIATELY |
|
- name: repositoryName |
|
value: 'REPO_NAME' |
|
- name: awsCredentials |
|
value: 'IAM - automation-ecr-APPLICATION_NAME' |
|
- name: clientName |
|
value: 'CLIENT_NAME' |
|
- name: applicationName |
|
value: 'APPLICATION_NAME' |
|
- name: projectName |
|
value: 'TKXS%20PowerSuite' |
|
|
|
stages: |
|
- stage: PreBuildCheck |
|
displayName: 'Pre-Build Check(s)' |
|
jobs: |
|
- job: Verify |
|
steps: |
|
- task: Bash@3 |
|
displayName: 'Verifying Build Request Source' |
|
inputs: |
|
targetType: 'inline' |
|
script: | |
|
if [ $(echo $(Build.SourceBranch) | awk -F '/' '{print $3}') == "master" ] || [ $(echo $(Build.SourceBranch) | awk -F '/' '{print $3}') == "hotfix" ]; then |
|
echo "Branch confirmed, proceeding . . ." |
|
else |
|
echo "##vso[task.LogIssue type=error;]Only Master and Hotfix branches are valid for this pipeline." |
|
echo "Build Reason: $(Build.Reason)" |
|
echo "Branch Detected: $(echo $(Build.SourceBranch) | awk -F '/' '{print $3}')" |
|
exit 1 |
|
fi |
|
- task: Bash@3 |
|
name: 'BuildLinkage' |
|
displayName: 'Verifying Work Linkage Candidates' |
|
inputs: |
|
targetType: 'inline' |
|
script: | |
|
# Associative array is used to ensure a unique list of User Story IDs |
|
declare -A STORIES |
|
|
|
# API call to get commit information and data for a specific Azure Pipelines build |
|
BUILD_CHANGES=$(curl -s -u $(ADO_API_KEY) -X GET "https://dev.azure.com/tkxs/TKXS%20PowerSuite/_apis/build/builds/$(Build.BuildId)/changes?api-version=6.0") |
|
|
|
# Get the number of commits in an Azure Pipelines build |
|
COMMIT_COUNT=$(echo $BUILD_CHANGES | jq -r .count) |
|
|
|
# Loop through each commit that leveraged the Azure Boards plugin and extract the Story ID |
|
for (( i=0; i<$COMMIT_COUNT; i++ )) |
|
do |
|
BUILD_MESSAGE=$(echo $BUILD_CHANGES | jq -r .value[$i].message) |
|
|
|
PLUGIN_STRINGS=( $(echo "$BUILD_MESSAGE" | grep -oE "(AB#)([0-9])+") ) |
|
|
|
for x in "${!PLUGIN_STRINGS[@]}" |
|
do |
|
STORY_ID="$(echo "${PLUGIN_STRINGS[$x]}" | grep -oE "([0-9])+")" |
|
|
|
if [ -z "${STORIES[$STORY_ID]}" ]; then |
|
echo "Unique Story ID ($STORY_ID) found." |
|
STORIES[$STORY_ID]="TRUE" |
|
fi |
|
done |
|
done |
|
|
|
# Assign a special variable that is reachable across yaml stages |
|
echo "##vso[task.setvariable variable=StoryIDs;isOutput=true]${!STORIES[@]}" |
|
|
|
- stage: Build |
|
displayName: 'Build Project' |
|
dependsOn: PreBuildCheck |
|
condition: succeeded() |
|
variables: |
|
- name: StoryIDs |
|
value: $[ stageDependencies.PreBuildCheck.Verify.outputs['BuildLinkage.StoryIDs'] ] |
|
jobs: |
|
- job: Build |
|
steps: |
|
- template: ps-core-docker-build-template.yml@PSCorePipelineTemplates |
|
parameters: |
|
deployBuild: 'true' |
|
projectName: $(projectName) |
|
linkageIDs: $(StoryIDs) |
|
encryptionKey: $(encryptionKey) |
|
secretLocation: $(secretLocation) |
|
buildArgs: $(buildArgs) |
|
dockerComposeLocation: $(dockerComposeLocation) |
|
dockerComposeFileName: $(dockerComposeFileName) |
|
buildRepositoryName: $(buildRepositoryName) |
|
buildSourceVersion: $(buildSourceVersion) |
|
awsCredentials: $(awsCredentials) |
|
regionName: $(regionName) |
|
imageSource: $(imageSourcePush) |
|
repositoryName: $(repositoryName) |
|
|
|
# - stage: DEV |
|
# displayName: 'Deploy to DEV Environment' |
|
# dependsOn: |
|
# - PreBuildCheck |
|
# - Build |
|
# condition: and(dependencies.Build.result, 'Succeeded', eq('${{ parameters.deployDev }}', 'Yes')) |
|
# variables: |
|
# - name: StoryIDs |
|
# value: $[ stageDependencies.PreBuildCheck.Verify.outputs['BuildLinkage.StoryIDs'] ] |
|
# jobs: |
|
# - template: ps-core-docker-deploy-template.yml@PSCorePipelineTemplates |
|
# parameters: |
|
# stageName: Development |
|
# environmentName: dev |
|
# linkageIDs: $(StoryIDs) |
|
# clientName: $(clientName) |
|
# applicationName: $(applicationName) |
|
# projectName: $(projectName) |
|
# dockerCredentialLocation: $(dockerCredentialLocation) |
|
# herokuApiToken: $(herokuApiToken) |
|
# encryptionKey: $(encryptionKey) |
|
# buildRepositoryName: $(repositoryName) |
|
# buildSourceVersion: $(buildSourceVersion) |
|
# awsCredentials: $(awsCredentials) |
|
# regionName: $(regionName) |
|
# imageSource: $(imageSourcePull) |
|
# imageName: 'IMAGE_NAME' |
|
|
|
- stage: Production |
|
displayName: 'Deploy to Production Environment' |
|
dependsOn: |
|
- PreBuildCheck |
|
- Build |
|
condition: and(dependencies.Build.result, 'Succeeded', eq('${{ parameters.deployProd }}', 'Yes')) |
|
variables: |
|
- name: StoryIDs |
|
value: $[ stageDependencies.PreBuildCheck.Verify.outputs['BuildLinkage.StoryIDs'] ] |
|
jobs: |
|
- template: ps-core-docker-deploy-template.yml@PSCorePipelineTemplates |
|
parameters: |
|
stageName: Prod |
|
environmentName: prod |
|
linkageIDs: $(StoryIDs) |
|
clientName: $(clientName) |
|
applicationName: $(applicationName) |
|
projectName: $(projectName) |
|
dockerCredentialLocation: $(dockerCredentialLocation) |
|
herokuApiToken: $(herokuApiToken) |
|
encryptionKey: $(encryptionKey) |
|
buildRepositoryName: $(repositoryName) |
|
buildSourceVersion: $(buildSourceVersion) |
|
awsCredentials: $(awsCredentials) |
|
regionName: $(regionName) |
|
imageSource: $(imageSourcePull) |
|
imageName: 'IMAGE_NAME' |
Scaffold a new project: