在使用Azure Devops管道构建容器时,如何将变量传递给docker
我正在尝试用一个具有DDBB连接的PHP项目构建一个容器,并希望通过环境变量设置DDBB 我已经用管道变量定义了变量 我还在变量部分设置变量在使用Azure Devops管道构建容器时,如何将变量传递给docker,docker,azure-devops,azure-pipelines,Docker,Azure Devops,Azure Pipelines,我正在尝试用一个具有DDBB连接的PHP项目构建一个容器,并希望通过环境变量设置DDBB 我已经用管道变量定义了变量 我还在变量部分设置变量 variables: imageName: 'project' repositoryNameDes: 'portalweb-des/project' repositoryNamePro: 'portalweb-pro/project' connectionECRpredes: 'amazon container registry w-pr
variables:
imageName: 'project'
repositoryNameDes: 'portalweb-des/project'
repositoryNamePro: 'portalweb-pro/project'
connectionECRpredes: 'amazon container registry w-predes'
connectionECRpro: 'amazon container registry w-pro'
tName: $(Build.SourceBranchName)_$(Build.SourceVersion)
ecrRepositoryNameBaseUrl: '513537361685.dkr.ecr.eu-west-1.amazonaws.com'
dirNameS3: 'project'
bucketNameDes: 'cluster-drupal-des-deploy-s3'
deployOnECS: $[or(startsWith(variables['Build.SourceBranch'], 'refs/heads/tags/'), startsWith(variables['Build.SourceBranch'], 'refs/heads/develop'), startsWith(variables['Build.SourceBranch'], 'refs/heads/feature/generardocker'))]
ddbb_name: $(DDBB_NAME)
但是我不知道在构建时如何加载变量,我不确定是否有一个选项,所以设置环境变量,是否必须编写一个自定义构建来运行变量,或者如何创建它
steps:
- task: Docker@2
displayName: Build an image
inputs:
repository: $(imageName)
command: build
Dockerfile: Dockerfile
tags: $(tName)
- task: ECRPushImage@1
inputs:
ENV: '$(dev)'
awsCredentials: '$(connectionECRpredes)'
regionName: 'eu-west-1'
imageSource: 'imagename'
sourceImageName: '$(imageName)'
sourceImageTag: '$(tName)'
repositoryName: '$(repositoryNameDes)'
pushTag: $(tName)
谢谢。在最常见的情况下,您可以设置变量并在YAML文件中使用它们。这允许您跟踪版本控制系统中变量的更改。您还可以在管道设置UI(请参见经典选项卡)中定义变量,并在YAML中引用它们 下面的示例演示如何设置两个变量,
configuration
和platform
,并在后面的步骤中使用它们。要在YAML语句中使用变量,请将其包装在$()
中
有关详细信息,请查看以下链接:
您在构建过程中是否遇到任何错误?
# Set variables once
variables:
configuration: debug
platform: x64
steps:
# Use them once
- task: MSBuild@1
inputs:
solution: solution1.sln
configuration: $(configuration) # Use the variable
platform: $(platform)
# Use them again
- task: MSBuild@1
inputs:
solution: solution2.sln
configuration: $(configuration) # Use the variable
platform: $(platform)