Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cli/azd/pkg/azdo/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package azdo

import (
"context"
"encoding/json"
"fmt"
"strings"

Expand Down Expand Up @@ -116,6 +117,7 @@ func CreatePipeline(
if err != nil {
return nil, err
}
EscapeBuildDefinitionVariables(buildDefinitionVariables)
definition.Variables = buildDefinitionVariables
definition, err := client.UpdateDefinition(ctx, build.UpdateDefinitionArgs{
Definition: definition,
Expand All @@ -140,6 +142,7 @@ func CreatePipeline(
return nil, err
}

EscapeBuildDefinitionVariables(createDefinitionArgs.Definition.Variables)
newBuildDefinition, err := client.CreateDefinition(ctx, *createDefinitionArgs)
if err != nil {
return nil, err
Expand All @@ -148,6 +151,21 @@ func CreatePipeline(
return newBuildDefinition, nil
}

func EscapeBuildDefinitionVariables(vars *map[string]build.BuildDefinitionVariable) {
for key, variable := range *vars {
if variable.Value != nil {
original := *variable.Value
b, _ := json.Marshal(original)
s := string(b)
if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
s = s[1 : len(s)-1]
}
variable.Value = &s
(*vars)[key] = variable
}
}
}

func getDefinitionVariables(
env *environment.Environment,
credentials *entraid.AzureCredentials,
Expand Down
15 changes: 15 additions & 0 deletions cli/azd/pkg/pipeline/github_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ func (p *GitHubCiProvider) configurePipeline(
}
}

JsonEscapeVariables(toBeSetSecrets, toBeSetVariables)

// set the new variables and secrets
for key, value := range toBeSetSecrets {
if err := p.ghCli.SetSecret(ctx, repoSlug, key, value); err != nil {
Expand All @@ -999,6 +1001,19 @@ func (p *GitHubCiProvider) configurePipeline(
}, nil
}

func JsonEscapeVariables(vars ...map[string]string) {
for _, m := range vars {
for key, value := range m {
b, _ := json.Marshal(value)
s := string(b)
if len(s) >= 2 && s[0] == '"' && s[len(s)-1] == '"' {
s = s[1 : len(s)-1]
}
m[key] = s
}
}
}

// workflow is the implementation for a CiPipeline for GitHub
type workflow struct {
repoDetails *gitRepositoryDetails
Expand Down
Loading