Skip to content

Instantly share code, notes, and snippets.

@marcosborges
Created October 5, 2022 19:16
Show Gist options
  • Save marcosborges/69a82b0d1c794516be6601707fff2d29 to your computer and use it in GitHub Desktop.
Save marcosborges/69a82b0d1c794516be6601707fff2d29 to your computer and use it in GitHub Desktop.
- bash: |
echo "##vso[task.setvariable variable=project]${{parameters.project}}"
echo "vso[task.setvariable variable=project]${{parameters.project}}"
echo "##vso[task.setvariable variable=env_dev_k8s_sc]${{parameters.env_dev_k8s_sc}}"
echo "vso[task.setvariable variable=env_dev_k8s_sc]${{parameters.env_dev_k8s_sc}}"
echo "##vso[task.setvariable variable=env_uat_k8s_sc]${{parameters.env_uat_k8s_sc}}"
echo "vso[task.setvariable variable=env_uat_k8s_sc]${{parameters.env_uat_k8s_sc}}"
echo "##vso[task.setvariable variable=env_prd_k8s_sc]${{parameters.env_prd_k8s_sc}}"
echo "vso[task.setvariable variable=env_prd_k8s_sc]${{parameters.env_prd_k8s_sc}}"
export TOKEN="Authorization: Basic $(echo -n ":${SYSTEM_AUTH}" | base64 -w 0)"
echo "##vso[task.setvariable variable=TOKEN]${TOKEN}"
displayName: Export variables
env:
SYSTEM_AUTH: "$(AZURE_PAT_TOKEN)"
###########
# PROJECT #
###########
- bash: |
echo "##vso[task.setvariable variable=project_name]${PROJECT_NAME}"
echo "vso[task.setvariable variable=project_name]${PROJECT_NAME}"
PROJECT_NAME_URL_ENCODED=`echo -n ${PROJECT_NAME} | jq -sRr @uri`
echo "##vso[task.setvariable variable=project_name_url_encoded]${PROJECT_NAME_URL_ENCODED}"
echo "vso[task.setvariable variable=project_name_url_encoded]${PROJECT_NAME_URL_ENCODED}"
displayName: Project set vars
env:
PROJECT_NAME: "$(project)"
- bash: |
PROJECT_ID=$(curl -s "${URL}" --header "${AUTH}" --header "Content-Type: application/json" | jq --raw-output '.id //empty')
echo PROJECT_ID=${PROJECT_ID}
echo "##vso[task.setvariable variable=project_id]${PROJECT_ID}"
echo "vso[task.setvariable variable=project_id]${PROJECT_ID}"
if [[ -z "${PROJECT_ID}" ]]; then
echo "##vso[task.setvariable variable=project_not_exists]yes"
echo "vso[task.setvariable variable=project_not_exists]yes"
else
echo "##vso[task.setvariable variable=project_not_exists]no"
echo "vso[task.setvariable variable=project_not_exists]no"
fi
displayName: Project check exists
env:
URL: "$(azuredevops_base_url)/_apis/projects/$(project_name_url_encoded)?api-version=6.0"
AUTH: "$(TOKEN)"
################
# ENVIRONMENTS #
################
- bash: |
echo $(curl -s -X POST ${URL} --header "${AUTH}" --header 'Content-Type: application/json;charset=utf-8' --data-raw "{\"name\":\"env-default-develop\", \"description\":\"Description for ${PROJECT_NAME}\"}")
displayName: Environment dev creating
continueOnError: true
env:
URL: "$(azuredevops_base_url)/$(project_id)/_apis/distributedtask/environments?api-version=5.0-preview.1"
AUTH: "$(TOKEN)"
PROJECT_NAME: "$(project_name)"
- bash: |
echo $(curl -s -X POST ${URL} --header "${AUTH}" --header 'Content-Type: application/json;charset=utf-8' --data-raw "{\"name\":\"env-default-homolog\", \"description\":\"Description for ${PROJECT_NAME}\"}")
displayName: Environment uat creating
continueOnError: true
env:
URL: "$(azuredevops_base_url)/$(project_id)/_apis/distributedtask/environments?api-version=5.0-preview.1"
AUTH: "$(TOKEN)"
PROJECT_NAME: "$(project_name)"
- bash: |
echo $(curl -s -X POST ${URL} --header "${AUTH}" --header 'Content-Type: application/json;charset=utf-8' --data-raw "{\"name\":\"env-default-production\", \"description\":\"Description for ${PROJECT_NAME}\"}")
displayName: Environment prd creating
continueOnError: true
env:
URL: "$(azuredevops_base_url)/$(project_id)/_apis/distributedtask/environments?api-version=5.0-preview.1"
AUTH: "$(TOKEN)"
PROJECT_NAME: "$(project_name)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment