我如何将Docker图像标签传递给Spinnaker Webhook以使用* Run Job *阶段触发管道

时间:2019-06-26 19:16:05

标签: docker webhooks continuous-deployment docker-registry spinnaker

我有一个大三角帆管道,上面有一个运行作业类型的(运行容器)。该配置具有要运行的映像的名称,但是标签明确指出它将在运行时解析。我创建了一个 Docker Registry 触发器,该触发器确实确实可以自行解析标签名称。当我开始手动执行时,对话框会显示一个下拉菜单供我选择标记(如果未设置 Docker Registry 触发器,则不会发生这种情况)。到目前为止, Docker Registry Manual Execution 触发器都可以正常工作。

问题 出现在Webhook触发器上。我收到一条Status: TERMINAL的消息:

No tag found for image gcr.io/xxxx in trigger context.

我尝试过在参数中传递标记。它不起作用。

1 个答案:

答案 0 :(得分:0)

我对 webhooks + Run Job 阶段也有类似的要求,使用 spinnaker 表达式就可以了。

按照以下步骤解决:

  1. 添加两个自动触发器 - Docker 注册表和 Webhooks
"triggers": [
    {
      "account": "gcr",
      "enabled": true,
      "expectedArtifactIds": [
        "ARTIFACT_ID_PLACEHOLDER"
      ],
      "fromTrigger": true,
      "organization": "ORG_PLACEHOLDER",
      "registry": "gcr.io",
      "repository": "ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
      "tag": "${trigger['artifacts'][0]['version']}",
      "type": "docker"
    },
    {
      "enabled": true,
      "expectedArtifactIds": [
        "ARTIFACT_ID_PLACEHOLDER"
      ],
      "source": "WEBHOOK_PLACEHOLDER",
      "type": "webhook"
    }
  ]
  1. 添加预期工件
"expectedArtifacts": [
    {
      "defaultArtifact": {},
      "displayName": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
      "id": "ARTIFACT_ID_PLACEHOLDER",
      "matchArtifact": {
        "artifactAccount": "docker-registry",
        "id": "MATCH_ARTIFACT_ID_PLACEHOLDER",
        "name": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
        "type": "docker/image"
      },
      "useDefaultArtifact": true,
      "usePriorArtifact": false
    }
  ]
  1. 更新图片描述
    "imageDescription": {
       "account": "gcr",
       "fromTrigger": false,
       "imageId": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER:${trigger['artifacts'][0]['version']}",
       "registry": "gcr.io",
       "repository": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
       "tag": "${trigger['artifacts'][0]['version']}"
    }

最终 JSON:

{
  "appConfig": {},
  "expectedArtifacts": [
    {
      "defaultArtifact": {},
      "displayName": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
      "id": "ARTIFACT_ID_PLACEHOLDER",
      "matchArtifact": {
        "artifactAccount": "docker-registry",
        "id": "MATCH_ARTIFACT_ID_PLACEHOLDER",
        "name": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
        "type": "docker/image"
      },
      "useDefaultArtifact": true,
      "usePriorArtifact": false
    }
  ],
  "keepWaitingPipelines": false,
  "lastModifiedBy": "",
  "limitConcurrent": true,
  "spelEvaluator": "v4",
  "stages": [
    {
      "account": "ACCOUNT_PLACEHOLDER",
      "annotations": {},
      "application": "APPLICATIONNAME_PLACEHOLDER",
      "cloudProvider": "kubernetes",
      "cloudProviderType": "kubernetes",
      "containers": [
        {
          "args": [],
          "command": [],
          "envFrom": [],
          "envVars": [],
          "imageDescription": {
            "account": "gcr",
            "fromTrigger": false,
            "imageId": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER${trigger['artifacts'][0]['version']}",
            "registry": "gcr.io",
            "repository": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
            "tag": "${trigger['artifacts'][0]['version']}"
          },
          "imagePullPolicy": "ALWAYS",
          "limits": {},
          "name": "CONTAINER_NAME_PLACEHOLDER",
          "ports": [
            {
              "containerPort": 80,
              "name": "http",
              "protocol": "TCP"
            }
          ],
          "requests": {},
          "volumeMounts": []
        }
      ],
      "dnsPolicy": "ClusterFirst",
      "expectedArtifacts": [
        {
          "defaultArtifact": {},
          "displayName": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
          "id": "ARTIFACT_ID_PLACEHOLDER",
          "matchArtifact": {
            "artifactAccount": "docker-registry",
            "id": "MATCH_ARTIFACT_ID_PLACEHOLDER",
            "name": "gcr.io/ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
            "type": "docker/image"
          },
          "useDefaultArtifact": false,
          "usePriorArtifact": false
        }
      ],
      "labels": {},
      "name": "STAGE_NAME_PLACEHOLDER",
      "namespace": "default",
      "nodeSelector": {},
      "refId": "1",
      "requisiteStageRefIds": [],
      "serviceAccountName": "",
      "type": "runJob",
      "volumeSources": []
    }
  ],
  "triggers": [
    {
      "account": "gcr",
      "enabled": true,
      "expectedArtifactIds": [
        "ARTIFACT_ID_PLACEHOLDER"
      ],
      "fromTrigger": true,
      "organization": "ORG_PLACEHOLDER",
      "registry": "gcr.io",
      "repository": "ORG_PLACEHOLDER/IMAGE_NAME_PLACEHOLDER",
      "tag": "${trigger['artifacts'][0]['version']}",
      "type": "docker"
    },
    {
      "enabled": true,
      "expectedArtifactIds": [
        "ARTIFACT_ID_PLACEHOLDER"
      ],
      "source": "WEBHOOK_PLACEHOLDER",
      "type": "webhook"
    }
  ],
  "updateTs": ""
}

注意:在上述 JSON 配置中根据您的要求替换 XXXX_PLACEHOLDER,例如“ORG_PLACEHOLDER”、“IMAGE_NAME_PLACEHOLDER”等。