Jenkinsfile 中 PodTemplate 内的字符串插值

问题描述 投票:0回答:1

我正在尝试在 podtemplate 中添加 image_tag 和区域的值,但它不起作用。 错误

failed to add image information to the policy rule context: invalid image 'aws-cli:${image_version}' (bad image: docker.io/aws-cli:${image_version}, defaultRegistry: docker.io, enableDefaultRegistryMutation: true: invalid reference format)

我正在使用这个插件https://plugins.jenkins.io/kubernetes/

image_version = '2.15.40'
region = 'us-east-1'
podTemplate(yaml: '''
    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        label: label
    spec:
     containers:
     - name: aws-cli:${image_version}
       image: 
       env:
       - name: AWS_REGION
         value: ${region}
       resources:
         requests:
           cpu: "2"
           memory: "3Gi"
         limits:
           cpu: "2"
           memory: "3Gi"
       alwaysPullImage: true
       tty: true
       securityContext:
         privileged: true
''')
kubernetes jenkins jenkins-plugins cicd jenkins-kubernetes
1个回答
0
投票

您正在使用三重单引号字符串

'''
,它不进行变量插值。您需要使用三重双引号字符串
"""
来代替。请参阅 groovy docs

© www.soinside.com 2019 - 2024. All rights reserved.