简体   繁体   中英

Is it possible to integrate AWS Codepipeline and Jenkins in such a way?

I'm trying to set up a pipeline for CI for a project, which is heavily using AWS stack. We already have Bitbucket and Jenkins servers, so ideally I would like to avoid the creation of infrastructure components with duplicating functionality.

What I would like to get: Jenkins executes unit/integration tests, builds artifacts and then triggers Codepipeline, which deploys CF stacks and performs end-to-end tests. I was able to create a primitive pipeline with a combination of AWS steps plugin , S3 and Codepipeline.

Jenkinsfile:

#!groovy

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building..'
                sh "mvn clean package"
            }
        }
        stage('S3upload') {
            steps {
                withAWS(region:'us-east-1',credentials:'JENKINS') {
                    s3Upload(bucket: 'somebucket', workingDir:'target', includePathPattern:'some.jar');

                }
            }
        }
    }
}

Codepipeline:

{
    "pipeline": {
        "name": "SomePipeline",
        <...>
        ,
        "stages": [
            {
                "name": "Source",
                "actions": [
                    {
                        "name": "Source",
                        "actionTypeId": {
                            "category": "Source",
                            "owner": "AWS",
                            "provider": "S3",
                            "version": "1"
                        },
                        "runOrder": 1,
                        "configuration": {
                            "PollForSourceChanges": "false",
                            "S3Bucket": "somebucket",
                            "S3ObjectKey": "some.jar"
                        },
                        "outputArtifacts": [
                            {
                                "name": "SourceArtifact"
                            }
                        ],
                        "inputArtifacts": [],
                        "region": "us-east-1"
                    }
                ]
            },
            {
                "name": "DeployCognitoStack",
                "actions": [
                    {
                        "name": "DeployCognitoStack",
                        "actionTypeId": {
                            "category": "Deploy",
                            "owner": "AWS",
                            "provider": "CloudFormation",
                            "version": "1"
                        },
                        "runOrder": 1,
                        "configuration": {
                            "ActionMode": "CREATE_UPDATE",
                            "Capabilities": "CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND",
                            "RoleArn": "arn:aws:iam::*:role/CloudFormationRole",
                            "StackName": "cognitostacktest",
                            "TemplatePath": "SourceArtifact::cognito-stack.yaml"
                        },
                        "outputArtifacts": [],
                        "inputArtifacts": [
                            {
                                "name": "SourceArtifact"
                            }
                        ],
                        "region": "us-east-1"
                    }
                ]
            },
            {
                "name": "DeployLambdaStack",
                "actions": [
                    {
                        "name": "DeployLambdaStack",
                        "actionTypeId": {
                            "category": "Deploy",
                            "owner": "AWS",
                            "provider": "CloudFormation",
                            "version": "1"
                        },
                        "runOrder": 1,
                        "configuration": {
                            "ActionMode": "CREATE_UPDATE",
                            "Capabilities": "CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND",
                            "RoleArn": "arn:aws:iam::*:role/CloudFormationRole",
                            "StackName": "lambdatest",
                            "TemplatePath": "SourceArtifact::lambda-stack.yaml"
                        },
                        "outputArtifacts": [],
                        "inputArtifacts": [
                            {
                                "name": "SourceArtifact"
                            }
                        ],
                        "region": "us-east-1"
                    }
                ]
            },
            <here should be test stage>
        ],
        "version": 5
    }
}

What I do not like is that I need to look separately to the results of Jenkins job execution and to results of Codepipeline execution. I would prefer to see everything in Jenkins.

Which options do I see:

  1. Forget about Codepipeline, use only commands from AWS Steps plugin to deploy test stacks and execute end-to-end tests by scripts.

  2. Follow AWS four-steps pipeline tutorial . If I understand it correctly, this solution will require active polling of SCM and pulling code to AWS.

Am I missing something?

As now CodePipeline has direct Bitbucket cloud support [1] and also supports the jenkins as custom stage directly [2] you can setup the CodePipeline which will use the bitbucket as source stage and jenkins actions as part of stage so that we can still use the jenkins for all the testing and once there is success from the jenkis we can go ahead and do the Deployment to CloudFormation.

[1] https://aws.amazon.com/about-aws/whats-new/2019/12/aws-codepipeline-now-supports-atlassian-bitbucket-cloud/

[2] https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-four-stage-pipeline.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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