Azure Pipelines SystemsManagerRunCommand@1任务实例标签配置求助
针对标签匹配实例的需求,instanceTags的正确格式为JSON对象:键对应标签名称,值对应标签值的数组(单个值时也可直接用字符串)。
比如你需要匹配标签example值为value1或value2的实例,配置写法如下:
instanceTags: '{"example": ["value1", "value2"]}'
如果需要同时匹配多个标签(需全部满足),可扩展JSON对象:
instanceTags: '{"Environment": ["Production"], "Role": ["WebServer", "AppServer"]}'
修改后的完整任务配置示例:
- task: SystemsManagerRunCommand@1 displayName: "Install latest CwAgent" inputs: regionName: 'eu-central-1' awsCredentials: my credentials documentName: 'AWS-ConfigureAWSPackage' documentParameters: > { "action": ["Install"], "name": ["AmazonCloudWatchAgent"], "version": ["latest"] } comment: 'Install latest version of cloud watch agent on target machines' instanceSelector: 'fromTags' instanceTags: '{"example": ["value1", "value2"]}' # 替换为你的目标标签键值对 - task: SystemsManagerRunCommand@1 displayName: "Update agent with latest config" inputs: regionName: 'eu-central-1' awsCredentials: my credentials documentName: 'AmazonCloudWatch-ManageAgent' documentParameters: > { "action": ["configure"], "mode": ["ec2"], "optionalConfigurationSource": ["ssm"], "optionalConfigurationLocation": ["/CWAgent/CustomConfiguration.json"], "optionalRestart": ["yes"] } comment: 'manage agent to use our custom config' instanceSelector: 'fromTags' instanceTags: '{"example": ["value1", "value2"]}' # 替换为你的目标标签键值对
注意:JSON字符串需用单引号包裹,避免与YAML的双引号语法冲突;若标签仅需匹配单个值,可简化为{"example": "value1"}。
内容的提问来源于stack exchange,提问作者Jack Hurley
相关产品推荐
相关产品推荐

