带有 jenkins 构建阶段的代码管道的 AWS Cloudformation 模板

AWS Cloudformation template for a codepipeline with jenkins build stage

我需要为 build/test 的 Jenkins 集成管道编写 CFT。我发现这个 documentation 可以为 jenkins 阶段设置 ActionTypeId。但是这个文档没有指定如何设置 jenkins serverserver url。而且我也不清楚在哪里给 Jenkins 提供商名称。它是在 ActionTypeId 还是在 configuration 属性中?

我在互联网上也找不到此用例的任何示例。

请提供使用 AWS Cloudformation 模板为 AWS Codepipeline 设置 Jenkins Action Provider 的正确示例。

以下是我根据从上述文档中学到的知识编写的示例 cft 的一部分。

"stages": [
    {
        "name": "Jenkins",
        "actions": [
            ...
            {
                "name": "Jenkins Build",
                "actionTypeId": {
                    "category": "Build",
                    "owner": "Custom",
                    "provider": "Jenkins",
                    "version": "1"
                },
                "runOrder": 2,
                "configuration": {
                    ???
                },
                ...
            }
        ]
    },
    ...
]

我缺少的信息是我需要创建一个 Custom Action 以使用 Jenkins 作为我的代码管道的 Action 提供程序。

首先我添加了如下自定义操作:

JenkinsCustomActionType: 
    Type: AWS::CodePipeline::CustomActionType
    Properties: 
        Category: Build 
        Provider: !Ref JenkinsProviderName
        Version: 1
        ConfigurationProperties: 
            - 
                Description: "The name of the build project must be provided when this action is added to the pipeline." 
                Key: true 
                Name: ProjectName 
                Queryable: false
                Required: true 
                Secret: false 
                Type: String 
        InputArtifactDetails: 
            MaximumCount: 5
            MinimumCount: 0 
        OutputArtifactDetails: 
            MaximumCount: 5
            MinimumCount: 0 
        Settings: 
            EntityUrlTemplate: !Join ['', [!Ref JenkinsServerURL, "/job/{Config:ProjectName}/"]]
            ExecutionUrlTemplate: !Join ['', [!Ref JenkinsServerURL, "/job/{Config:ProjectName}/{ExternalExecutionId}/"]]
        Tags:
            - Key: Name
              Value: custom-jenkins-action-type

The jenkins server URL is given in the settings for Custom Action and the Jenkins provider name is given for Provider. Which were the issues I had initially.

然后配置流水线阶段如下:

DevPipeline:
    Type: AWS::CodePipeline::Pipeline
    DependsOn: JenkinsCustomActionType
    Properties:
        Name: Dev-CodePipeline
        RoleArn:
            Fn::GetAtt: [ CodePipelineRole, Arn ]
        Stages:
            ...
            - Name: DevBuildVerificationTest
              Actions:
                  - Name: JenkinsDevBVT
                    ActionTypeId:
                        Category: Build
                        Owner: Custom
                        Version: 1
                        Provider: !Ref JenkinsProviderName
                    Configuration:
                        # JenkinsDevBVTProjectName - Jenkins Job name defined as a parameter in the CFT
                        ProjectName: !Ref JenkinsDevBVTProjectName
                    RunOrder: 4

必须在管道之前创建自定义操作。因此 DependsOn: JenkinsCustomActionType