Product not published as expected

Abierto
#793 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
azure
Área
api, cloud, devops

Línea de trabajo

Comienza revisando publisher.yml y publisher-with-env.yml; después inspecciona el archivo configuration.qa.yaml referenciado y los artefactos de producto extraídos. Ejecuta el pipeline de publicación para QA y rastrea cómo se seleccionan los ajustes del producto. Se considera terminado cuando el producto se publica en el entorno de destino con su configuración específica del entorno, en lugar de los valores de desarrollo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Release version

APIOPS v5.1.4

Question Details

Hi i going to create APIM for Dev, QA, Prod env for my client this is new requirement. i am having issue when i publish the product from dev to qa, and prod. this is below listed activity i have done.

1, created 3 APIM like dev, qa and prod envs.
2, manually create APIs, backends, named values, products, subscriptions in dev env.
3, Extract the dev env APIM resources and entities using extractor pipeline in azure devops pipeline.
4, artifacts were stored in the repos, this contains APIs, backends, named values etc.
5, now i am going to publish the all above created entities in dev to qa using config.qa.yaml. this contains qa env based backend url, named values secrets and product policy yamls. backend and named values were created as expected. but product is publishing as expected from config.qa.yaml file.
6, backend, named values were published from config.qa.yml file, but product has been published which is same like dev env getting from artifacts.
7, so product has not been published as expected

Note:
provide me the exact yaml file for publish the product to another envs, because we are having unique token for individual envs.

kindly provide me the solution ASAP, i have been working for long time. but still issue not resolved.

because we are new for APIOPS and myself only explain about APIOPS to the client. so provide me the detailed step by step solution.

this is my publisher.yml files.

trigger: none

branches:

include:

- main

paths:

exclude:

- tools/*

parameters:

  • name: LOCATION_NAME
    displayName: 'Location name:'
    default: cus
    values:

    • cus
  • name: ENV_CHOICE
    displayName: 'Environment name:'
    default: dev
    values:

    • poc
    • dev
    • qa
    • qa2
    • pims
    • prd

- name: COUNT

displayname: 'count values:'

default: 01

values:

- 01

- 02

- 03

- 04

- name: PROJECT

displayname: 'Project name:'

default: ars

values:

- ars

  • name: COMMIT_ID
    type: string
    displayName: Choose "publish-all-artifacts-in-repo" only when you want to force republishing all artifacts (e.g. after build failure). Otherwise stick with the default behavior of "publish-artifacts-in-last-commit"
    default: publish-artifacts-in-last-commit
    values:
    • publish-artifacts-in-last-commit
    • publish-all-artifacts-in-repo

variables:

  • group: ARS-apim-automation

  • name: System.Debug
    value: false

  • name: API_OUTPUT_FOLDER_PATH
    value: 'artifacts'

  • name: RG_NAME
    ${{ if and(eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_POC)
    ${{ if and(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_DEV)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_QA)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa2'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_QA2)
    ${{ if and(eq(parameters.ENV_CHOICE, 'pims'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_PIMS)
    ${{ if and(eq(parameters.ENV_CHOICE, 'prd'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_PRD)

  • name: APIM_INSTANCE_NAME
    ${{ if and(eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_POC)
    ${{ if and(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_DEV)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_QA)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa2'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_QA2)
    ${{ if and(eq(parameters.ENV_CHOICE, 'pims'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_PIMS)
    ${{ if and(eq(parameters.ENV_CHOICE, 'prd'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_PRD)

  • name: SERVICE_CONN_NAME
    ${{ if and(or(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.ENV_CHOICE, 'qa2')), eq(parameters.LOCATION_NAME, 'cus')) }}:
    value: $(SERVICE_CONNECTION_NAME_NPRD)
    ${{ else }}:
    value: $(SERVICE_CONNECTION_NAME_PRD)

  • name: ENV_NAME
    value: 'apim-${{ parameters.ENV_CHOICE }}-${{ parameters.LOCATION_NAME }}'

stages:

  • stage: push_APIM_changes_to_${{ parameters.ENV_CHOICE }}
    displayName: Push APIM changes to ${{ parameters.ENV_CHOICE }}
    jobs:
    • deployment: push_APIM_changes_to_${{ parameters.ENV_CHOICE }}
      displayName: Push APIM changes to ${{ parameters.ENV_CHOICE }}
      pool:
      vmImage: ubuntu-latest
      environment: ${{ variables.ENV_NAME }}
      strategy:
      runOnce:
      deploy:
      steps:
      - template: run-publisher-with-env.yml
      parameters:
      API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: ${{ variables.API_OUTPUT_FOLDER_PATH }}
      RESOURCE_GROUP_NAME: ${{ variables.RG_NAME }}
      API_MANAGEMENT_SERVICE_NAME: ${{ variables.APIM_INSTANCE_NAME }}
      CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/tools/configs/${{ parameters.LOCATION_NAME }}/configuration.${{ parameters.ENV_CHOICE }}.yaml
      #CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/tools/configs/cus/configuration.qa.yaml
      ENVIRONMENT: ${{ variables.ENV_NAME }}
      COMMIT_ID: ${{ parameters.COMMIT_ID }}
      SERVICE_CONNECTION_NAME: ${{ variables.SERVICE_CONN_NAME }}

this is my publisher-with-env.yml:

parameters:

  • name: API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH
    type: string
    displayName: Folder where the artifacts reside
    default: "artifacts"
  • name: ENVIRONMENT
    type: string
    displayName: Environment to display
  • name: RESOURCE_GROUP_NAME
    default: ant-rg-apim-poc
    type: string
    displayName: Resource Group Name
  • name: API_MANAGEMENT_SERVICE_NAME
    type: string
    displayName: APIM Instance Name
    default: ""
  • name: CONFIGURATION_YAML_PATH
    type: string
    displayName: Optional configuration file (target environment publishing into)
  • name: COMMIT_ID
    type: string
    default: publish-artifacts-in-last-commit
  • name: SERVICE_CONNECTION_NAME
    type: string
    default: ARS-ApiOps

steps:

  • script: echo Provided configuration was ${{ parameters.CONFIGURATION_YAML_PATH }}
    displayName: Print the name of the yaml configuration file if provided

  • script: echo Provided app service name was ${{ parameters.API_MANAGEMENT_SERVICE_NAME }}
    displayName: Print the name of the apim service name if provided

  • checkout: self
    fetchDepth: 0

  • task: AzureCLI@2
    displayName: Set publishing variables
    inputs:
    azureSubscription: "${{parameters.SERVICE_CONNECTION_NAME}}"
    scriptType: pscore
    scriptLocation: inlineScript
    inlineScript: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_BEARER_TOKEN]$(az account get-access-token --query "accessToken" --output tsv)"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_CLIENT_ID]$env:servicePrincipalId"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_CLIENT_SECRET]$env:servicePrincipalKey"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_TENANT_ID]$env:tenantId"
    if (-not $env:AZURE_SUBSCRIPTION_ID) {
      $subscriptionCount = az account list --query "length([])" --output tsv
      if ($subscriptionCount -eq 1) {
          $subscriptionId = az account list --query "[0].id" --output tsv
          Write-Host "Setting AZURE_SUBSCRIPTION_ID environment variable to: $subscriptionId"
          Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_SUBSCRIPTION_ID]$($subscriptionId)"
      } 
      elseif ($subscriptionCount -gt 1) {
          Write-Host "Multiple subscriptions are accessible. Please set the AZURE_SUBSCRIPTION_ID environment variable manually."
          exit 1
      }
    }
    else {
      Write-Host "AZURE_SUBSCRIPTION_ID is already set to: $env:AZURE_SUBSCRIPTION_ID"
    }
    

    addSpnToEnvironment: true
    failOnStandardError: true

  • ${{ if ne(parameters.CONFIGURATION_YAML_PATH, '') }}:

    • task: qetza.replacetokens.replacetokens-task.replacetokens@6
      displayName: "Perform namevalue secret substitution in ${{ parameters.CONFIGURATION_YAML_PATH }}"
      inputs:
      sources: ${{ parameters.CONFIGURATION_YAML_PATH }}
      encoding: "auto"
      addBOM: true
      logLevel: "off"
      missingVarLog: "warn"
      missingVarAction: "none"
      tokenPrefix: "{#"
      tokenSuffix: "#}"
  • task: PowerShell@2
    displayName: Fetch publisher
    inputs:
    targetType: "inline"
    script: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    Write-Information "Downloading publisher..."
    $publisherFileName = "publisher.linux-x64"
    $publisherFinalFileName = "publisher"
    if ("$(Agent.OS)" -like "*win*") {
      $publisherFileName = "publisher.win-x64.exe"
      $publisherFinalFileName = "publisher.exe"
    }
    elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*arm*") {
      $publisherFileName = "publisher.osx-arm64"
    }
    elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*x86_64*") {
      $publisherFileName = "publisher.osx-x64"
    }
    
    $uri = "https://github.com/Azure/apiops/releases/download/$(apiops_release_version)/$publisherFileName"
    $destinationFilePath = Join-Path "$(Agent.TempDirectory)" $publisherFinalFileName
    Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"
    
    if ("$(Agent.OS)" -like "*linux*")
    {
      Write-Information "Setting file permissions..."
      & chmod +x "$destinationFilePath"
      if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
    }
    
    Write-Host "##vso[task.setvariable variable=PUBLISHER_FILE_PATH]$destinationFilePath"
    Write-Information "Execution complete."
    

    failOnStderr: true
    pwsh: true

  • task: PowerShell@2
    displayName: Run publisher for ${{ parameters.ENVIRONMENT}} environment
    inputs:
    targetType: "inline"
    script: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    & "$(PUBLISHER_FILE_PATH)"                
    if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}
    
    Write-Information "Execution complete."
    

    failOnStderr: true
    pwsh: true
    env:
    AZURE_BEARER_TOKEN: $(AZURE_BEARER_TOKEN)
    AZURE_CLIENT_ID: $(AZURE_CLIENT_ID)
    AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
    AZURE_TENANT_ID: $(AZURE_TENANT_ID)
    AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)
    AZURE_RESOURCE_GROUP_NAME: ${{ parameters.RESOURCE_GROUP_NAME }}
    API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: $(Build.SourcesDirectory)/${{ parameters.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
    ${{ if ne( parameters['API_MANAGEMENT_SERVICE_NAME'], '' ) }}:
    API_MANAGEMENT_SERVICE_NAME: ${{ parameters.API_MANAGEMENT_SERVICE_NAME }}
    ${{ if eq( parameters['COMMIT_ID'], 'publish-artifacts-in-last-commit' ) }}:
    COMMIT_ID: $(Build.SourceVersion)
    ${{ if ne( parameters['CONFIGURATION_YAML_PATH'], '' ) }}:
    CONFIGURATION_YAML_PATH: ${{ parameters.CONFIGURATION_YAML_PATH }}

check this above mentioned files and provide the steps.

Expected behavior

Hi i going to create APIM for Dev, QA, Prod env for my client this is new requirement. i am having issue when i publish the product from dev to qa, and prod. this is below listed activity i have done.

1, created 3 APIM like dev, qa and prod envs.
2, manually create APIs, backends, named values, products, subscriptions in dev env.
3, Extract the dev env APIM resources and entities using extractor pipeline in azure devops pipeline.
4, artifacts were stored in the repos, this contains APIs, backends, named values etc.
5, now i am going to publish the all above created entities in dev to qa using config.qa.yaml. this contains qa env based backend url, named values secrets and product policy yamls. backend and named values were created as expected. but product is publishing as expected from config.qa.yaml file.
6, backend, named values were published from config.qa.yml file, but product has been published which is same like dev env getting from artifacts.
7, so product has not been published as expected

Note:
provide me the exact yaml file for publish the product to another envs, because we are having unique token for individual envs.

kindly provide me the solution ASAP, i have been working for long time. but still issue not resolved.

because we are new for APIOPS and myself only explain about APIOPS to the client. so provide me the detailed step by step solution.

this is my publisher.yml files.

trigger: none

branches:

include:

- main

paths:

exclude:

- tools/*

parameters:

  • name: LOCATION_NAME
    displayName: 'Location name:'
    default: cus
    values:

    • cus
  • name: ENV_CHOICE
    displayName: 'Environment name:'
    default: dev
    values:

    • poc
    • dev
    • qa
    • qa2
    • pims
    • prd

- name: COUNT

displayname: 'count values:'

default: 01

values:

- 01

- 02

- 03

- 04

- name: PROJECT

displayname: 'Project name:'

default: ars

values:

- ars

  • name: COMMIT_ID
    type: string
    displayName: Choose "publish-all-artifacts-in-repo" only when you want to force republishing all artifacts (e.g. after build failure). Otherwise stick with the default behavior of "publish-artifacts-in-last-commit"
    default: publish-artifacts-in-last-commit
    values:
    • publish-artifacts-in-last-commit
    • publish-all-artifacts-in-repo

variables:

  • group: ARS-apim-automation

  • name: System.Debug
    value: false

  • name: API_OUTPUT_FOLDER_PATH
    value: 'artifacts'

  • name: RG_NAME
    ${{ if and(eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_POC)
    ${{ if and(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_DEV)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_QA)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa2'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_QA2)
    ${{ if and(eq(parameters.ENV_CHOICE, 'pims'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_PIMS)
    ${{ if and(eq(parameters.ENV_CHOICE, 'prd'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_PRD)

  • name: APIM_INSTANCE_NAME
    ${{ if and(eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_POC)
    ${{ if and(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_DEV)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_QA)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa2'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_QA2)
    ${{ if and(eq(parameters.ENV_CHOICE, 'pims'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_PIMS)
    ${{ if and(eq(parameters.ENV_CHOICE, 'prd'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_PRD)

  • name: SERVICE_CONN_NAME
    ${{ if and(or(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.ENV_CHOICE, 'qa2')), eq(parameters.LOCATION_NAME, 'cus')) }}:
    value: $(SERVICE_CONNECTION_NAME_NPRD)
    ${{ else }}:
    value: $(SERVICE_CONNECTION_NAME_PRD)

  • name: ENV_NAME
    value: 'apim-${{ parameters.ENV_CHOICE }}-${{ parameters.LOCATION_NAME }}'

stages:

  • stage: push_APIM_changes_to_${{ parameters.ENV_CHOICE }}
    displayName: Push APIM changes to ${{ parameters.ENV_CHOICE }}
    jobs:
    • deployment: push_APIM_changes_to_${{ parameters.ENV_CHOICE }}
      displayName: Push APIM changes to ${{ parameters.ENV_CHOICE }}
      pool:
      vmImage: ubuntu-latest
      environment: ${{ variables.ENV_NAME }}
      strategy:
      runOnce:
      deploy:
      steps:
      - template: run-publisher-with-env.yml
      parameters:
      API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: ${{ variables.API_OUTPUT_FOLDER_PATH }}
      RESOURCE_GROUP_NAME: ${{ variables.RG_NAME }}
      API_MANAGEMENT_SERVICE_NAME: ${{ variables.APIM_INSTANCE_NAME }}
      CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/tools/configs/${{ parameters.LOCATION_NAME }}/configuration.${{ parameters.ENV_CHOICE }}.yaml
      #CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/tools/configs/cus/configuration.qa.yaml
      ENVIRONMENT: ${{ variables.ENV_NAME }}
      COMMIT_ID: ${{ parameters.COMMIT_ID }}
      SERVICE_CONNECTION_NAME: ${{ variables.SERVICE_CONN_NAME }}

this is my publisher-with-env.yml:

parameters:

  • name: API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH
    type: string
    displayName: Folder where the artifacts reside
    default: "artifacts"
  • name: ENVIRONMENT
    type: string
    displayName: Environment to display
  • name: RESOURCE_GROUP_NAME
    default: ant-rg-apim-poc
    type: string
    displayName: Resource Group Name
  • name: API_MANAGEMENT_SERVICE_NAME
    type: string
    displayName: APIM Instance Name
    default: ""
  • name: CONFIGURATION_YAML_PATH
    type: string
    displayName: Optional configuration file (target environment publishing into)
  • name: COMMIT_ID
    type: string
    default: publish-artifacts-in-last-commit
  • name: SERVICE_CONNECTION_NAME
    type: string
    default: ARS-ApiOps

steps:

  • script: echo Provided configuration was ${{ parameters.CONFIGURATION_YAML_PATH }}
    displayName: Print the name of the yaml configuration file if provided

  • script: echo Provided app service name was ${{ parameters.API_MANAGEMENT_SERVICE_NAME }}
    displayName: Print the name of the apim service name if provided

  • checkout: self
    fetchDepth: 0

  • task: AzureCLI@2
    displayName: Set publishing variables
    inputs:
    azureSubscription: "${{parameters.SERVICE_CONNECTION_NAME}}"
    scriptType: pscore
    scriptLocation: inlineScript
    inlineScript: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_BEARER_TOKEN]$(az account get-access-token --query "accessToken" --output tsv)"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_CLIENT_ID]$env:servicePrincipalId"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_CLIENT_SECRET]$env:servicePrincipalKey"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_TENANT_ID]$env:tenantId"
    if (-not $env:AZURE_SUBSCRIPTION_ID) {
      $subscriptionCount = az account list --query "length([])" --output tsv
      if ($subscriptionCount -eq 1) {
          $subscriptionId = az account list --query "[0].id" --output tsv
          Write-Host "Setting AZURE_SUBSCRIPTION_ID environment variable to: $subscriptionId"
          Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_SUBSCRIPTION_ID]$($subscriptionId)"
      } 
      elseif ($subscriptionCount -gt 1) {
          Write-Host "Multiple subscriptions are accessible. Please set the AZURE_SUBSCRIPTION_ID environment variable manually."
          exit 1
      }
    }
    else {
      Write-Host "AZURE_SUBSCRIPTION_ID is already set to: $env:AZURE_SUBSCRIPTION_ID"
    }
    

    addSpnToEnvironment: true
    failOnStandardError: true

  • ${{ if ne(parameters.CONFIGURATION_YAML_PATH, '') }}:

    • task: qetza.replacetokens.replacetokens-task.replacetokens@6
      displayName: "Perform namevalue secret substitution in ${{ parameters.CONFIGURATION_YAML_PATH }}"
      inputs:
      sources: ${{ parameters.CONFIGURATION_YAML_PATH }}
      encoding: "auto"
      addBOM: true
      logLevel: "off"
      missingVarLog: "warn"
      missingVarAction: "none"
      tokenPrefix: "{#"
      tokenSuffix: "#}"
  • task: PowerShell@2
    displayName: Fetch publisher
    inputs:
    targetType: "inline"
    script: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    Write-Information "Downloading publisher..."
    $publisherFileName = "publisher.linux-x64"
    $publisherFinalFileName = "publisher"
    if ("$(Agent.OS)" -like "*win*") {
      $publisherFileName = "publisher.win-x64.exe"
      $publisherFinalFileName = "publisher.exe"
    }
    elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*arm*") {
      $publisherFileName = "publisher.osx-arm64"
    }
    elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*x86_64*") {
      $publisherFileName = "publisher.osx-x64"
    }
    
    $uri = "https://github.com/Azure/apiops/releases/download/$(apiops_release_version)/$publisherFileName"
    $destinationFilePath = Join-Path "$(Agent.TempDirectory)" $publisherFinalFileName
    Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"
    
    if ("$(Agent.OS)" -like "*linux*")
    {
      Write-Information "Setting file permissions..."
      & chmod +x "$destinationFilePath"
      if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
    }
    
    Write-Host "##vso[task.setvariable variable=PUBLISHER_FILE_PATH]$destinationFilePath"
    Write-Information "Execution complete."
    

    failOnStderr: true
    pwsh: true

  • task: PowerShell@2
    displayName: Run publisher for ${{ parameters.ENVIRONMENT}} environment
    inputs:
    targetType: "inline"
    script: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    & "$(PUBLISHER_FILE_PATH)"                
    if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}
    
    Write-Information "Execution complete."
    

    failOnStderr: true
    pwsh: true
    env:
    AZURE_BEARER_TOKEN: $(AZURE_BEARER_TOKEN)
    AZURE_CLIENT_ID: $(AZURE_CLIENT_ID)
    AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
    AZURE_TENANT_ID: $(AZURE_TENANT_ID)
    AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)
    AZURE_RESOURCE_GROUP_NAME: ${{ parameters.RESOURCE_GROUP_NAME }}
    API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: $(Build.SourcesDirectory)/${{ parameters.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
    ${{ if ne( parameters['API_MANAGEMENT_SERVICE_NAME'], '' ) }}:
    API_MANAGEMENT_SERVICE_NAME: ${{ parameters.API_MANAGEMENT_SERVICE_NAME }}
    ${{ if eq( parameters['COMMIT_ID'], 'publish-artifacts-in-last-commit' ) }}:
    COMMIT_ID: $(Build.SourceVersion)
    ${{ if ne( parameters['CONFIGURATION_YAML_PATH'], '' ) }}:
    CONFIGURATION_YAML_PATH: ${{ parameters.CONFIGURATION_YAML_PATH }}

check this above mentioned files and provide the steps.

Actual behavior

Hi i going to create APIM for Dev, QA, Prod env for my client this is new requirement. i am having issue when i publish the product from dev to qa, and prod. this is below listed activity i have done.

1, created 3 APIM like dev, qa and prod envs.
2, manually create APIs, backends, named values, products, subscriptions in dev env.
3, Extract the dev env APIM resources and entities using extractor pipeline in azure devops pipeline.
4, artifacts were stored in the repos, this contains APIs, backends, named values etc.
5, now i am going to publish the all above created entities in dev to qa using config.qa.yaml. this contains qa env based backend url, named values secrets and product policy yamls. backend and named values were created as expected. but product is publishing as expected from config.qa.yaml file.
6, backend, named values were published from config.qa.yml file, but product has been published which is same like dev env getting from artifacts.
7, so product has not been published as expected

Note:
provide me the exact yaml file for publish the product to another envs, because we are having unique token for individual envs.

kindly provide me the solution ASAP, i have been working for long time. but still issue not resolved.

because we are new for APIOPS and myself only explain about APIOPS to the client. so provide me the detailed step by step solution.

this is my publisher.yml files.

trigger: none

branches:

include:

- main

paths:

exclude:

- tools/*

parameters:

  • name: LOCATION_NAME
    displayName: 'Location name:'
    default: cus
    values:

    • cus
  • name: ENV_CHOICE
    displayName: 'Environment name:'
    default: dev
    values:

    • poc
    • dev
    • qa
    • qa2
    • pims
    • prd

- name: COUNT

displayname: 'count values:'

default: 01

values:

- 01

- 02

- 03

- 04

- name: PROJECT

displayname: 'Project name:'

default: ars

values:

- ars

  • name: COMMIT_ID
    type: string
    displayName: Choose "publish-all-artifacts-in-repo" only when you want to force republishing all artifacts (e.g. after build failure). Otherwise stick with the default behavior of "publish-artifacts-in-last-commit"
    default: publish-artifacts-in-last-commit
    values:
    • publish-artifacts-in-last-commit
    • publish-all-artifacts-in-repo

variables:

  • group: ARS-apim-automation

  • name: System.Debug
    value: false

  • name: API_OUTPUT_FOLDER_PATH
    value: 'artifacts'

  • name: RG_NAME
    ${{ if and(eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_POC)
    ${{ if and(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_DEV)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_QA)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa2'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_QA2)
    ${{ if and(eq(parameters.ENV_CHOICE, 'pims'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_PIMS)
    ${{ if and(eq(parameters.ENV_CHOICE, 'prd'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_PRD)

  • name: APIM_INSTANCE_NAME
    ${{ if and(eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_POC)
    ${{ if and(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_DEV)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_QA)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa2'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_QA2)
    ${{ if and(eq(parameters.ENV_CHOICE, 'pims'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_PIMS)
    ${{ if and(eq(parameters.ENV_CHOICE, 'prd'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_PRD)

  • name: SERVICE_CONN_NAME
    ${{ if and(or(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.ENV_CHOICE, 'qa2')), eq(parameters.LOCATION_NAME, 'cus')) }}:
    value: $(SERVICE_CONNECTION_NAME_NPRD)
    ${{ else }}:
    value: $(SERVICE_CONNECTION_NAME_PRD)

  • name: ENV_NAME
    value: 'apim-${{ parameters.ENV_CHOICE }}-${{ parameters.LOCATION_NAME }}'

stages:

  • stage: push_APIM_changes_to_${{ parameters.ENV_CHOICE }}
    displayName: Push APIM changes to ${{ parameters.ENV_CHOICE }}
    jobs:
    • deployment: push_APIM_changes_to_${{ parameters.ENV_CHOICE }}
      displayName: Push APIM changes to ${{ parameters.ENV_CHOICE }}
      pool:
      vmImage: ubuntu-latest
      environment: ${{ variables.ENV_NAME }}
      strategy:
      runOnce:
      deploy:
      steps:
      - template: run-publisher-with-env.yml
      parameters:
      API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: ${{ variables.API_OUTPUT_FOLDER_PATH }}
      RESOURCE_GROUP_NAME: ${{ variables.RG_NAME }}
      API_MANAGEMENT_SERVICE_NAME: ${{ variables.APIM_INSTANCE_NAME }}
      CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/tools/configs/${{ parameters.LOCATION_NAME }}/configuration.${{ parameters.ENV_CHOICE }}.yaml
      #CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/tools/configs/cus/configuration.qa.yaml
      ENVIRONMENT: ${{ variables.ENV_NAME }}
      COMMIT_ID: ${{ parameters.COMMIT_ID }}
      SERVICE_CONNECTION_NAME: ${{ variables.SERVICE_CONN_NAME }}

this is my publisher-with-env.yml:

parameters:

  • name: API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH
    type: string
    displayName: Folder where the artifacts reside
    default: "artifacts"
  • name: ENVIRONMENT
    type: string
    displayName: Environment to display
  • name: RESOURCE_GROUP_NAME
    default: ant-rg-apim-poc
    type: string
    displayName: Resource Group Name
  • name: API_MANAGEMENT_SERVICE_NAME
    type: string
    displayName: APIM Instance Name
    default: ""
  • name: CONFIGURATION_YAML_PATH
    type: string
    displayName: Optional configuration file (target environment publishing into)
  • name: COMMIT_ID
    type: string
    default: publish-artifacts-in-last-commit
  • name: SERVICE_CONNECTION_NAME
    type: string
    default: ARS-ApiOps

steps:

  • script: echo Provided configuration was ${{ parameters.CONFIGURATION_YAML_PATH }}
    displayName: Print the name of the yaml configuration file if provided

  • script: echo Provided app service name was ${{ parameters.API_MANAGEMENT_SERVICE_NAME }}
    displayName: Print the name of the apim service name if provided

  • checkout: self
    fetchDepth: 0

  • task: AzureCLI@2
    displayName: Set publishing variables
    inputs:
    azureSubscription: "${{parameters.SERVICE_CONNECTION_NAME}}"
    scriptType: pscore
    scriptLocation: inlineScript
    inlineScript: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_BEARER_TOKEN]$(az account get-access-token --query "accessToken" --output tsv)"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_CLIENT_ID]$env:servicePrincipalId"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_CLIENT_SECRET]$env:servicePrincipalKey"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_TENANT_ID]$env:tenantId"
    if (-not $env:AZURE_SUBSCRIPTION_ID) {
      $subscriptionCount = az account list --query "length([])" --output tsv
      if ($subscriptionCount -eq 1) {
          $subscriptionId = az account list --query "[0].id" --output tsv
          Write-Host "Setting AZURE_SUBSCRIPTION_ID environment variable to: $subscriptionId"
          Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_SUBSCRIPTION_ID]$($subscriptionId)"
      } 
      elseif ($subscriptionCount -gt 1) {
          Write-Host "Multiple subscriptions are accessible. Please set the AZURE_SUBSCRIPTION_ID environment variable manually."
          exit 1
      }
    }
    else {
      Write-Host "AZURE_SUBSCRIPTION_ID is already set to: $env:AZURE_SUBSCRIPTION_ID"
    }
    

    addSpnToEnvironment: true
    failOnStandardError: true

  • ${{ if ne(parameters.CONFIGURATION_YAML_PATH, '') }}:

    • task: qetza.replacetokens.replacetokens-task.replacetokens@6
      displayName: "Perform namevalue secret substitution in ${{ parameters.CONFIGURATION_YAML_PATH }}"
      inputs:
      sources: ${{ parameters.CONFIGURATION_YAML_PATH }}
      encoding: "auto"
      addBOM: true
      logLevel: "off"
      missingVarLog: "warn"
      missingVarAction: "none"
      tokenPrefix: "{#"
      tokenSuffix: "#}"
  • task: PowerShell@2
    displayName: Fetch publisher
    inputs:
    targetType: "inline"
    script: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    Write-Information "Downloading publisher..."
    $publisherFileName = "publisher.linux-x64"
    $publisherFinalFileName = "publisher"
    if ("$(Agent.OS)" -like "*win*") {
      $publisherFileName = "publisher.win-x64.exe"
      $publisherFinalFileName = "publisher.exe"
    }
    elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*arm*") {
      $publisherFileName = "publisher.osx-arm64"
    }
    elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*x86_64*") {
      $publisherFileName = "publisher.osx-x64"
    }
    
    $uri = "https://github.com/Azure/apiops/releases/download/$(apiops_release_version)/$publisherFileName"
    $destinationFilePath = Join-Path "$(Agent.TempDirectory)" $publisherFinalFileName
    Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"
    
    if ("$(Agent.OS)" -like "*linux*")
    {
      Write-Information "Setting file permissions..."
      & chmod +x "$destinationFilePath"
      if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
    }
    
    Write-Host "##vso[task.setvariable variable=PUBLISHER_FILE_PATH]$destinationFilePath"
    Write-Information "Execution complete."
    

    failOnStderr: true
    pwsh: true

  • task: PowerShell@2
    displayName: Run publisher for ${{ parameters.ENVIRONMENT}} environment
    inputs:
    targetType: "inline"
    script: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    & "$(PUBLISHER_FILE_PATH)"                
    if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}
    
    Write-Information "Execution complete."
    

    failOnStderr: true
    pwsh: true
    env:
    AZURE_BEARER_TOKEN: $(AZURE_BEARER_TOKEN)
    AZURE_CLIENT_ID: $(AZURE_CLIENT_ID)
    AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
    AZURE_TENANT_ID: $(AZURE_TENANT_ID)
    AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)
    AZURE_RESOURCE_GROUP_NAME: ${{ parameters.RESOURCE_GROUP_NAME }}
    API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: $(Build.SourcesDirectory)/${{ parameters.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
    ${{ if ne( parameters['API_MANAGEMENT_SERVICE_NAME'], '' ) }}:
    API_MANAGEMENT_SERVICE_NAME: ${{ parameters.API_MANAGEMENT_SERVICE_NAME }}
    ${{ if eq( parameters['COMMIT_ID'], 'publish-artifacts-in-last-commit' ) }}:
    COMMIT_ID: $(Build.SourceVersion)
    ${{ if ne( parameters['CONFIGURATION_YAML_PATH'], '' ) }}:
    CONFIGURATION_YAML_PATH: ${{ parameters.CONFIGURATION_YAML_PATH }}

check this above mentioned files and provide the steps.

Reproduction Steps

Hi i going to create APIM for Dev, QA, Prod env for my client this is new requirement. i am having issue when i publish the product from dev to qa, and prod. this is below listed activity i have done.

1, created 3 APIM like dev, qa and prod envs.
2, manually create APIs, backends, named values, products, subscriptions in dev env.
3, Extract the dev env APIM resources and entities using extractor pipeline in azure devops pipeline.
4, artifacts were stored in the repos, this contains APIs, backends, named values etc.
5, now i am going to publish the all above created entities in dev to qa using config.qa.yaml. this contains qa env based backend url, named values secrets and product policy yamls. backend and named values were created as expected. but product is publishing as expected from config.qa.yaml file.
6, backend, named values were published from config.qa.yml file, but product has been published which is same like dev env getting from artifacts.
7, so product has not been published as expected

Note:
provide me the exact yaml file for publish the product to another envs, because we are having unique token for individual envs.

kindly provide me the solution ASAP, i have been working for long time. but still issue not resolved.

because we are new for APIOPS and myself only explain about APIOPS to the client. so provide me the detailed step by step solution.

this is my publisher.yml files.

trigger: none

branches:

include:

- main

paths:

exclude:

- tools/*

parameters:

  • name: LOCATION_NAME
    displayName: 'Location name:'
    default: cus
    values:

    • cus
  • name: ENV_CHOICE
    displayName: 'Environment name:'
    default: dev
    values:

    • poc
    • dev
    • qa
    • qa2
    • pims
    • prd

- name: COUNT

displayname: 'count values:'

default: 01

values:

- 01

- 02

- 03

- 04

- name: PROJECT

displayname: 'Project name:'

default: ars

values:

- ars

  • name: COMMIT_ID
    type: string
    displayName: Choose "publish-all-artifacts-in-repo" only when you want to force republishing all artifacts (e.g. after build failure). Otherwise stick with the default behavior of "publish-artifacts-in-last-commit"
    default: publish-artifacts-in-last-commit
    values:
    • publish-artifacts-in-last-commit
    • publish-all-artifacts-in-repo

variables:

  • group: ARS-apim-automation

  • name: System.Debug
    value: false

  • name: API_OUTPUT_FOLDER_PATH
    value: 'artifacts'

  • name: RG_NAME
    ${{ if and(eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_POC)
    ${{ if and(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_DEV)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_QA)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa2'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_QA2)
    ${{ if and(eq(parameters.ENV_CHOICE, 'pims'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_PIMS)
    ${{ if and(eq(parameters.ENV_CHOICE, 'prd'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(RESOURCE_GROUP_NAME_PRD)

  • name: APIM_INSTANCE_NAME
    ${{ if and(eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_POC)
    ${{ if and(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_DEV)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_QA)
    ${{ if and(eq(parameters.ENV_CHOICE, 'qa2'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_QA2)
    ${{ if and(eq(parameters.ENV_CHOICE, 'pims'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_PIMS)
    ${{ if and(eq(parameters.ENV_CHOICE, 'prd'), eq(parameters.LOCATION_NAME, 'cus') )}}:
    value: $(APIM_NAME_PRD)

  • name: SERVICE_CONN_NAME
    ${{ if and(or(eq(parameters.ENV_CHOICE, 'dev'), eq(parameters.ENV_CHOICE, 'poc'), eq(parameters.ENV_CHOICE, 'qa'), eq(parameters.ENV_CHOICE, 'qa2')), eq(parameters.LOCATION_NAME, 'cus')) }}:
    value: $(SERVICE_CONNECTION_NAME_NPRD)
    ${{ else }}:
    value: $(SERVICE_CONNECTION_NAME_PRD)

  • name: ENV_NAME
    value: 'apim-${{ parameters.ENV_CHOICE }}-${{ parameters.LOCATION_NAME }}'

stages:

  • stage: push_APIM_changes_to_${{ parameters.ENV_CHOICE }}
    displayName: Push APIM changes to ${{ parameters.ENV_CHOICE }}
    jobs:
    • deployment: push_APIM_changes_to_${{ parameters.ENV_CHOICE }}
      displayName: Push APIM changes to ${{ parameters.ENV_CHOICE }}
      pool:
      vmImage: ubuntu-latest
      environment: ${{ variables.ENV_NAME }}
      strategy:
      runOnce:
      deploy:
      steps:
      - template: run-publisher-with-env.yml
      parameters:
      API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: ${{ variables.API_OUTPUT_FOLDER_PATH }}
      RESOURCE_GROUP_NAME: ${{ variables.RG_NAME }}
      API_MANAGEMENT_SERVICE_NAME: ${{ variables.APIM_INSTANCE_NAME }}
      CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/tools/configs/${{ parameters.LOCATION_NAME }}/configuration.${{ parameters.ENV_CHOICE }}.yaml
      #CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/tools/configs/cus/configuration.qa.yaml
      ENVIRONMENT: ${{ variables.ENV_NAME }}
      COMMIT_ID: ${{ parameters.COMMIT_ID }}
      SERVICE_CONNECTION_NAME: ${{ variables.SERVICE_CONN_NAME }}

this is my publisher-with-env.yml:

parameters:

  • name: API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH
    type: string
    displayName: Folder where the artifacts reside
    default: "artifacts"
  • name: ENVIRONMENT
    type: string
    displayName: Environment to display
  • name: RESOURCE_GROUP_NAME
    default: ant-rg-apim-poc
    type: string
    displayName: Resource Group Name
  • name: API_MANAGEMENT_SERVICE_NAME
    type: string
    displayName: APIM Instance Name
    default: ""
  • name: CONFIGURATION_YAML_PATH
    type: string
    displayName: Optional configuration file (target environment publishing into)
  • name: COMMIT_ID
    type: string
    default: publish-artifacts-in-last-commit
  • name: SERVICE_CONNECTION_NAME
    type: string
    default: ARS-ApiOps

steps:

  • script: echo Provided configuration was ${{ parameters.CONFIGURATION_YAML_PATH }}
    displayName: Print the name of the yaml configuration file if provided

  • script: echo Provided app service name was ${{ parameters.API_MANAGEMENT_SERVICE_NAME }}
    displayName: Print the name of the apim service name if provided

  • checkout: self
    fetchDepth: 0

  • task: AzureCLI@2
    displayName: Set publishing variables
    inputs:
    azureSubscription: "${{parameters.SERVICE_CONNECTION_NAME}}"
    scriptType: pscore
    scriptLocation: inlineScript
    inlineScript: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_BEARER_TOKEN]$(az account get-access-token --query "accessToken" --output tsv)"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_CLIENT_ID]$env:servicePrincipalId"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_CLIENT_SECRET]$env:servicePrincipalKey"
    Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_TENANT_ID]$env:tenantId"
    if (-not $env:AZURE_SUBSCRIPTION_ID) {
      $subscriptionCount = az account list --query "length([])" --output tsv
      if ($subscriptionCount -eq 1) {
          $subscriptionId = az account list --query "[0].id" --output tsv
          Write-Host "Setting AZURE_SUBSCRIPTION_ID environment variable to: $subscriptionId"
          Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_SUBSCRIPTION_ID]$($subscriptionId)"
      } 
      elseif ($subscriptionCount -gt 1) {
          Write-Host "Multiple subscriptions are accessible. Please set the AZURE_SUBSCRIPTION_ID environment variable manually."
          exit 1
      }
    }
    else {
      Write-Host "AZURE_SUBSCRIPTION_ID is already set to: $env:AZURE_SUBSCRIPTION_ID"
    }
    

    addSpnToEnvironment: true
    failOnStandardError: true

  • ${{ if ne(parameters.CONFIGURATION_YAML_PATH, '') }}:

    • task: qetza.replacetokens.replacetokens-task.replacetokens@6
      displayName: "Perform namevalue secret substitution in ${{ parameters.CONFIGURATION_YAML_PATH }}"
      inputs:
      sources: ${{ parameters.CONFIGURATION_YAML_PATH }}
      encoding: "auto"
      addBOM: true
      logLevel: "off"
      missingVarLog: "warn"
      missingVarAction: "none"
      tokenPrefix: "{#"
      tokenSuffix: "#}"
  • task: PowerShell@2
    displayName: Fetch publisher
    inputs:
    targetType: "inline"
    script: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    Write-Information "Downloading publisher..."
    $publisherFileName = "publisher.linux-x64"
    $publisherFinalFileName = "publisher"
    if ("$(Agent.OS)" -like "*win*") {
      $publisherFileName = "publisher.win-x64.exe"
      $publisherFinalFileName = "publisher.exe"
    }
    elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*arm*") {
      $publisherFileName = "publisher.osx-arm64"
    }
    elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*x86_64*") {
      $publisherFileName = "publisher.osx-x64"
    }
    
    $uri = "https://github.com/Azure/apiops/releases/download/$(apiops_release_version)/$publisherFileName"
    $destinationFilePath = Join-Path "$(Agent.TempDirectory)" $publisherFinalFileName
    Invoke-WebRequest -Uri "$uri" -OutFile "$destinationFilePath"
    
    if ("$(Agent.OS)" -like "*linux*")
    {
      Write-Information "Setting file permissions..."
      & chmod +x "$destinationFilePath"
      if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
    }
    
    Write-Host "##vso[task.setvariable variable=PUBLISHER_FILE_PATH]$destinationFilePath"
    Write-Information "Execution complete."
    

    failOnStderr: true
    pwsh: true

  • task: PowerShell@2
    displayName: Run publisher for ${{ parameters.ENVIRONMENT}} environment
    inputs:
    targetType: "inline"
    script: |
    Set-StrictMode -Version Latest
    $ErrorActionPreference = "Stop"
    $VerbosePreference = "Continue"
    $InformationPreference = "Continue"

    & "$(PUBLISHER_FILE_PATH)"                
    if ($LASTEXITCODE -ne 0) { throw "Running publisher failed."}
    
    Write-Information "Execution complete."
    

    failOnStderr: true
    pwsh: true
    env:
    AZURE_BEARER_TOKEN: $(AZURE_BEARER_TOKEN)
    AZURE_CLIENT_ID: $(AZURE_CLIENT_ID)
    AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
    AZURE_TENANT_ID: $(AZURE_TENANT_ID)
    AZURE_SUBSCRIPTION_ID: $(AZURE_SUBSCRIPTION_ID)
    AZURE_RESOURCE_GROUP_NAME: ${{ parameters.RESOURCE_GROUP_NAME }}
    API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: $(Build.SourcesDirectory)/${{ parameters.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
    ${{ if ne( parameters['API_MANAGEMENT_SERVICE_NAME'], '' ) }}:
    API_MANAGEMENT_SERVICE_NAME: ${{ parameters.API_MANAGEMENT_SERVICE_NAME }}
    ${{ if eq( parameters['COMMIT_ID'], 'publish-artifacts-in-last-commit' ) }}:
    COMMIT_ID: $(Build.SourceVersion)
    ${{ if ne( parameters['CONFIGURATION_YAML_PATH'], '' ) }}:
    CONFIGURATION_YAML_PATH: ${{ parameters.CONFIGURATION_YAML_PATH }}

check this above mentioned files and provide the steps.

Lenguaje dominante
C#
Estrellas
448
Forks
247
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Azure/apiops

Todos los issues de Azure/apiops

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.