我无法将参数从我的 azure yaml 传递到我的 cloudformation yaml。我收到以下错误:
##[error]ValidationError: Parameters: [EnvironmentType] must have values
没有任何称为“EnvironmentType”的内容通过 azure yml 传递到 cloudformation yml。
azure-pipeline.yaml
pool:
name: AWS
variables:
ArtifactName: update-email
stages:
- stage: Build
displayName: Build Stage
...
- stage: DeployToDev
displayName: 'Deploy To Dev'
variables:
EnvironmentType: 'dev'
AwsCredentials: '${{ variables.EnvironmentType }}-xx'
AwsRegion: 'eu-central-1'
CodeBucket: 's3-$(EnvironmentType)-xx'
BucketPrefix: 'xx-$(ArtifactName)'
StackName: 'clf-$(EnvironmentType)-xx'
jobs:
- job: DeployToDev
steps:
...
- task: AmazonWebServices.aws-vsts-tools.CloudFormationCreateOrUpdateStack.CloudFormationCreateOrUpdateStack@1
displayName: 'Create/Update Stack: $(StackName)'
inputs:
awsCredentials: ${{ variables.AwsCredentials }}
regionName: $(AwsRegion)
stackName: $(StackName)
templateFile: '$(ArtifactName)/clf-xx-$(EnvironmentType).yml'
parameters: |
EnvironmentType=$(EnvironmentType)
clf.yaml
Parameters:
EnvironmentType:
Description: The deployment environment type.
Type: String
AllowedValues:
- dev
- prod
Resources:
xx:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Sub "lbd-${EnvironmentType}-xx"
...
我也尝试过:
- task: AmazonWebServices.aws-vsts-tools.CloudFormationCreateOrUpdateStack.CloudFormationCreateOrUpdateStack@1
displayName: 'Create/Update Stack: $(StackName)'
inputs:
awsCredentials: ${{ variables.AwsCredentials }}
regionName: $(AwsRegion)
stackName: $(StackName)
templateFile: '$(ArtifactName)/clf-xx-$(EnvironmentType).yml'
templateParameters: |
- ParameterKey: EnvironmentType
ParameterValue: ${{variables.EnvironmentType}}
还有
- task: AmazonWebServices.aws-vsts-tools.CloudFormationCreateOrUpdateStack.CloudFormationCreateOrUpdateStack@1
displayName: 'Create/Update Stack: $(StackName)'
inputs:
awsCredentials: ${{ variables.AwsCredentials }}
regionName: $(AwsRegion)
stackName: $(StackName)
templateFile: '$(ArtifactName)/clf-xx-$(EnvironmentType).yml'
parameters: |
- ParameterKey: EnvironmentType
ParameterValue: ${{variables.EnvironmentType}}
我知道我可以使用 ssm,但我想知道我是否想继续使用 CloudFormationCreateOrUpdateStack 任务的解决方案。
我在这里遗漏了什么吗?是否可以通过CloudFormationCreateOrUpdateStack任务将参数从azure yml传递到cloudformation yml?
提前致谢
“AWS CloudFormation 创建/更新堆栈任务”中没有属性“参数”。
如果想将参数传递到您的AWS模板,您应该按照erik258的建议将“模板参数源”设置为内联。另外还可以使用模板参数文件。例如:
parameters:
deploymentEnvironment: '' # development, staging, production, etc
awsCredentials: '' # service connection name
region: '' # the AWS region
steps:
- task: CloudFormationCreateOrUpdateStack@1
displayName: 'Create/Update Stack: Staging-Deployment'
inputs:
awsCredentials: '${{ parameters.awsCredentials }}'
regionName: '${{ parameters.region }}'
stackName: 'my-stack-name'
useChangeSet: true
changeSetName: 'my-stack-name-changeset'
templateFile: 'my-aws-cloudformation-template.yml'
templateParametersFile: '${{ parameters.deploymentEnvironment }}/parameters.json'
captureStackOutputs: asVariables
captureAsSecuredVars: false
您可以从使用 Azure DevOps 参数在 AWS 账户之间切换查看详细信息。