Skip to content

riboseinc/aws-codecommit-trigger-plugin

Repository files navigation

AWS CodeCommit Trigger Plugin

aws codecommit trigger?style=flat square aws codecommit trigger?style=flat square :license apache blue

aws codecommit trigger plugin

Introduction

A Jenkins plugin that triggers jobs on repo update events by AWS CodeCommit, through the AWS Simple Queue Service (SQS) and Simple Notification Service (SNS).

The advantage over the original AWS SQS Plugin that this plugin allows subscribing to multiple branches using the same SQS queue, meaning that:

  • you no longer need to create a SQS queue per CodeCommit repo

  • an update to the dev branch will no longer trigger all jobs that subscribe to that CodeCommit repo.

The original AWS SQS Plugin was written (and still maintained) by Markus Pfeiffer of M-Way Solutions GmbH.

Use JIRA to report issues / feature requests

Quick Setup With Terraform

Use the tf-codecommit-sqs module to create your CodeCommit repos created with provided linkage with SQS/SNS.

Manual Setup

General steps to config your Amazon Services:

  1. Create a CodeCommit Repo

  2. Open the Repo, create Triggers that will connect to a webhook through Amazon Simple Notification Service (SNS)

  3. Create SNS Topic subscribe to a Simple Queue Service (SQS) queue

  4. Open the SQS queue, do queue actions to subscribe it to SNS Topic

  5. Make sure the AWS Credentials used for this Plugin has Permission to

    • sqs:ReceiveMessage

    • sqs:DeleteMessage

    • sqs:DeleteMessageBatch

    • sqs:GetQueueAttributes

    • sqs:ListQueues (optional)

Jenkins System Configuration

Jenkins configuration test
  1. Go to Jenkins > Manage Jenkins > Configure System on your Jenkins

  2. Go to AWS Code Commit Trigger SQS Plugin

  3. Configure a queue

    • Select the name of the queue you just created (the list auto-loaded using selected AWS Credentials)

    • Select "Aws Credentials" from the list or click on button "Add Credentials" to create one

    • Access Key ID and Secret Access Key is setup using AWS Credentials

    • NOT support for IAM Roles and IAM MFA Token

  4. Click on Test access

You should see a success message.

If you get an error message make sure you entered the credentials correctly. If you still see errors double check the user, group and permissions you set up on Amazon Web Services.

Jenkins Job Configuration

Freestyle Job

  1. Go to Jenkins > $job

  2. Click on Configure

  3. Scroll down to Build Triggers

  4. Check Build when a message is published to an SQS queue

  5. Select the queue you created previously

For cost savings, the plugin does not start monitoring a queue until at least one job has been configured to listen to messages from a queue.

You can use the same queue for multiple jobs or you can create a new queue for each job. Keep in mind that monitoring multiple queues will increase the amount of requests your Jenkins will have to send to AWS.

Normally you would use the same queue and topic for multiple jobs, but for billing purposes it may be easier to use multiple queues, especially if you’re running builds on behalf of a customer.

Pipeline Job

Sample Pipeline Script

Jenkinsfile
node {
    stage('Preparation') {
        sh "echo 'Preparation phase'"

        checkout scm: [
            $class           : 'GitSCM',
            userRemoteConfigs: [[url: "https://git-codecommit.us-west-2.amazonaws.com/v1/repos/testjenkins", credentialsId: "test"]], //mins
            branches         : [[name: "refs/heads/master"]],
        ], poll: false
    }

    stage('Build') {
        sh "echo 'Build phase'"
    }

    stage('Results') {
        sh "echo 'Result phase'"
    }
}

Configuration sample

Pipeline configuration test

Test your setup

If you’ve set up everything correctly pushing a change to the Git repository on CodeCommit should now trigger a build on Jenkins. If nothing happens, make sure the job has been set to use messages posted to SQS as a build trigger.

Build trigger configuration

Pipeline usage sample

Contributing

  1. Fork it

  2. Create your feature branch (git checkout -b my-new-feature)

  3. Write your code and tests

  4. Ensure all tests still pass (mvn clean verify -Pit)

  5. Commit your changes (git commit -am 'Add some feature')

  6. Push to the branch (git push origin my-new-feature)

  7. Create new pull request

Authors

AWS CodeCommit Trigger Plugin is provided by Ribose Inc. (GitHub page: Ribose Inc.)

License

Full text: Apache License

About

Jenkins plugin for triggering jobs with AWS CodeCommit repo updates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages