Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Question]How to change the settings to only publish certain API? Is it supported for this tool or latest version? #777

Copy link
Copy link
@setyg

Description

@setyg
Issue body actions

Release version

apiops verion v5.1.4

Question Details

unable to publish individual APIM even I configure the yaml:

trigger: none
parameters:

  • name: API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH
    type: string
    displayName: Folder where the artifacts reside
    default: "artifacts"
  • 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
  • name: SH01_API_NAMES
    type: object
    displayName: List of API folders to publish
    default:
    • sh01-kabsa
    • sh01-resource
  • name: CONFIGURATION_YAML_PATH
    type: string
    displayName: Optional configuration file
    default: "$(Build.SourcesDirectory)/configuration.uat.yaml"

variables:

  • group: apim-automation
  • name: System.Debug
    value: true

stages:

  • stage: push_changes_to_uat_APIM
    displayName: Push changes to Uat APIM
    jobs:
    • job: push_changes_to_Uat_APIM
      displayName: Push changes to Uat APIM
      pool:
      vmImage: ubuntu-latest
      steps:

      • script: echo Provided configuration was $(Build.SourcesDirectory)/configuration.uat.yaml
        displayName: Print the name of the yaml configuration file if provided

      • script: echo Provided app service name was $(APIM_NAME_UAT)
        displayName: Print the name of the apim service name if provided

      • checkout: self
        fetchDepth: 0

      • task: AzureCLI@2
        displayName: Set publishing variables
        inputs:
        azureSubscription: "$(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

      只保留 SH01_API_NAMES 指定的 API 文件夹

      • task: PowerShell@2
        displayName: Filter only selected APIs
        inputs:
        targetType: "inline"
        script: |
        $ErrorActionPreference = "Stop"
        $srcRoot = "$(Build.SourcesDirectory)/${{ parameters.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}/apis"
        $dstRoot = "$(Build.ArtifactStagingDirectory)/filtered-apis"
        New-Item -ItemType Directory -Force -Path $dstRoot | Out-Null
        $apis = @()
        foreach ($api in "${{ join(',', parameters.SH01_API_NAMES) }}".Split(',')) {
        $src = Join-Path $srcRoot $api
        if (Test-Path $src) {
        Copy-Item $src $dstRoot -Recurse
        $apis += $api
        }
        }
        Write-Host "Filtered APIs: $($apis -join ',')"
        # 覆盖原 artifacts/apis 目录
        Remove-Item $srcRoot -Recurse -Force
        Move-Item $dstRoot $srcRoot

      replacetokens@3 task will need to be installed to use

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

        • task: qetza.replacetokens.replacetokens-task.replacetokens@3
          displayName: "Perform namevalue secret substitution in $(Build.SourcesDirectory)/configuration.uat.yaml"
          inputs:
          targetFiles: $(Build.SourcesDirectory)/configuration.uat.yaml
          encoding: "auto"
          writeBOM: true
          verbosity: "off"
          actionOnMissing: "warn"
          keepToken: false
          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 Uat 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: $(RESOURCE_GROUP_NAME_UAT)
        API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH: $(Build.SourcesDirectory)/${{ parameters.API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH }}
        API_MANAGEMENT_SERVICE_NAME: $(APIM_NAME_UAT)
        ${{ if eq( parameters['COMMIT_ID'], 'publish-artifacts-in-last-commit' ) }}:
        COMMIT_ID: $(Build.SourceVersion)
        CONFIGURATION_YAML_PATH: $(Build.SourcesDirectory)/configuration.uat.yaml

How to change the settings to only publish certain API? Is it supported for this tool or latest version?

Expected behavior

The effect I want to achieve is to only publish the code of the corresponding API management project that has been modified in the git repo, while the code submitted through the git repo for other projects should not be published to the API management instance. In brief, I want to achieve the release of specified API projects through a single pipeline script, rather than publishing all APIs.

Actual behavior

My pipelines script has deployed all the code submitted through the git repo to the instance of API management

Reproduction Steps

  1. Establish the binding between the API management instance and the Azure Git repo
  2. Modify the corresponding code in sh01-kabsa, sh02-resource, and api-test
    3.run piplines

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.