Azure / Azure/apiops

[BUG] One or more fields contain incorrect values:","details":[{"code":"ValidationError","target":"name","message":"Tag with the same name already exists.

Offen
#855 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
448
Forks
247
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### Release version

APIOps release version 6.0.2

### Describe the bug

##[error]Unhandled exception. System.Net.Http.HttpRequestException: HTTP request to URI https://management.azure.com/subscriptions/***/resourceGroups/prd-int-it-rg-eaiapim/providers/Microsoft.ApiManagement/service/prd-eaiapimint-apim-01/tags/programs-673e0548c5f6294c3c3daf2f?api-version=2023-09-01-preview failed with status code 400. Content is '{"error":{"code":"ValidationError","message":"One or more fields contain incorrect values:","details":[{"code":"ValidationError","target":"name","message":"Tag with the same name already exists."}]}}'.

### Expected behavior

I am trying to publish artifacts from test to prod. This APIM instance already exist and it should be fine and I should be able to overwrite the instance somehow.

### Actual behavior

But it keeps failing with these errors that already exist, It should overwrite it without complaining. I am try to sync the changes from test to PROD.

### Reproduction Steps

parameters:
- name: API_MANAGEMENT_SERVICE_OUTPUT_FOLDER_PATH
type: string
displayName: Folder where the artifacts reside
- name: ENVIRONMENT
type: string
displayName: Environment to display
- name: RESOURCE_GROUP_NAME
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
default: ""
- name: SUBSCRIPTION_ID
type: string
displayName: Azure Subscription ID
default: ""
- name: COMMIT_ID
type: string
default: publish-artifacts-in-last-commit

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: "$(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"
$paramSubscriptionId = "${{ parameters.SUBSCRIPTION_ID }}"
if ($paramSubscriptionId) {
Write-Host "Using subscription ID from parameter: $paramSubscriptionId"
Write-Host "##vso[task.setvariable issecret=true;variable=AZURE_SUBSCRIPTION_ID]$paramSubscriptionId"
}
elseif (-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

# replacetokens@6 task will need to be installed to use
- ${{ 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
verbosity: "off"
missingVarAction: "none"
missingVarLog: "warn"
tokenPattern: "custom"
tokenPrefix: "{#"
tokenSuffix: "#}"

- task: PowerShell@2
displayName: Fetch publisher
inputs:
targetType: "inline"
script: |
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$VerbosePreference = "Continue"
$InformationPreference = "Continue"

Write-Information "Setting name variables..."
$releaseFileName = "publisher-linux-x64.zip"
$executableFileName = "publisher"

if ("$(Agent.OS)" -like "*win*") {
$releaseFileName = "publisher-win-x64.zip"
$executableFileName = "publisher.exe"
}
elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*arm*") {
$releaseFileName = "publisher-osx-arm64.zip"
}
elseif ("$(Agent.OS)" -like "*mac*" -and "$(Agent.OSArchitecture)" -like "*x86_64*") {
$releaseFileName = "publisher-osx-x64.zip"
}

Write-Information "Downloading release..."
$uri = "https://github.com/Azure/apiops/releases/download/$(apiops_release_version)/$releaseFileName"
$downloadFilePath = Join-Path "$(Agent.TempDirectory)" $releaseFileName
Invoke-WebRequest -Uri "$uri" -OutFile "$downloadFilePath"

Write-Information "Extracting release..."
$executableFolderPath = Join-Path "$(Agent.TempDirectory)" "publisher"
Expand-Archive -Path "$downloadFilePath" -DestinationPath "$executableFolderPath"
$executableFilePath = Join-Path "$executableFolderPath" $executableFileName

Write-Information "Setting file permissions..."
if ("$(Agent.OS)" -like "*linux*")
{
& chmod +x "$executableFilePath"
if ($LASTEXITCODE -ne 0) { throw "Setting file permissions failed."}
}

Write-Host "##vso[task.setvariable variable=PUBLISHER_FILE_PATH]$executableFilePath"
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 }}

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start by reproducing the failure with the shown Azure DevOps pipeline and the publisher executable against an APIM instance containing an existing tag. Read the publisher's API Management tag handling and verify that synchronization updates or safely replaces duplicate tags; done means publishing the test artifacts to production succeeds without the duplicate-name validation error.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
azure, csharp, powershell
Bereich
api, ci-cd, cloud
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.