问题描述
我需要使用 Jenkins 更新 statefulset。更准确地说,是在 init 容器中更新主题。 这是我在 Jenkins 中使用的代码(在终端中运行良好):
kubectl patch statefulset test-deploy -n test -p '{"spec": {"template": {"spec":{"initContainers":[{"name": "theme","image": "xxxx.dkr.ecr.us-east-1.amazonaws.com/testrepo:latest"}]}}}}'
我得到的错误:期待 '}',找到 '-'@第 293 行,第 192 列。 年龄": "xxx.dkr.ecr.us-east-1.am
当我将双引号改为单引号时: kubectl 补丁 statefulset keycloak-job-deploy -n ci-environment-dev -p '{'spec': {'template': {'spec':{'initContainers':[{'name': 'theme','image ': '837236160124.dkr.ecr.us-east-1.amazonaws.com/ci/keycloak-theme-thermo-fisher-develop:develop-0.0.1-3'}]}}}}'
我明白了:
来自服务器的错误 (BadRequest): 寻找对象键字符串开头的无效字符 's'
你能帮我弄清楚引号有什么问题吗,我应该使用什么命令?
解决方法
我想通了。它与 Groovy 中的筛选有关。这是正确的版本:
kubectl patch statefulset test-deploy --namespace=${namespace} -p '{\"spec\": {\"template\": {\"spec\":{\"initContainers\":[{\"name\": \"theme\",\"image\": \"${theme}\"}]}}}}'