简体   繁体   English

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

[英]AWS Cloudformation template for a codepipeline with jenkins build stage

I need to write a CFT for pipeline with Jenkins integration for build/test.我需要为带有 Jenkins 集成的管道编写 CFT 以进行构建/测试。 I found this documentation to setup ActionTypeId for the jenkins stage.我发现此文档为 jenkins 阶段设置ActionTypeId But this doc does not specify how to set the server url of the jenkins server .但是这个文档没有说明如何设置jenkins 服务器server url And also it is not clear to me where to give the Jenkins Provider name .而且我也不清楚在哪里给出Jenkins Provider name Is it in the ActionTypeId or in configuration properties?它是在ActionTypeId中还是在configuration属性中?

I could not find any example for this use case in the internet as well.我在互联网上也找不到此用例的任何示例。

Please provide a proper example for setup Jenkins Action Provider for AWS Codepipeline using AWS Cloudformation template.请提供适当的示例,以使用 AWS Cloudformation 模板为 AWS Codepipeline 设置 Jenkins 操作提供程序。

Following is a section from the sample cft I wrote from what I learnt from above doc.以下是我从上面的文档中学到的示例 cft 中的一部分。

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

The piece of information which was missing for me was that I need to create a Custom Action to use Jenkins as the Action provider for my codepipeline.我缺少的一条信息是我需要创建一个自定义操作来使用 Jenkins 作为我的代码管道的操作提供程序。

First I added the custom action as below:首先,我添加了如下自定义操作:

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 . jenkins 服务器 URL 在自定义操作的settings中给出, Jenkins 提供者名称在Provider中给出。 Which were the issues I had initially.这是我最初遇到的问题。

Then configure the pipeline stage as following:然后配置管道阶段如下:

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

The Custom Action has to be created before the Pipeline.必须在流水线之前创建自定义操作。 Hence DependsOn: JenkinsCustomActionType因此DependsOn: JenkinsCustomActionType

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM