9

I am currently developing a personal project on master. Every time I push to origin master a build is triggered on CodePipeline. As I am the only developer working on this project and don't want to bother with branches at this stage it would be nice to skip unnecessary builds. I wouldn't mind pushing to another branch, but it's a small annoyance.

CodeShip allows you to skip a build by including --skip-ci in your commit message. Is something like this possible with CodePipeline?

None of my Google searches have yielded results. The CodePipeline documentation makes no mention of such a feature either.

Joe Hawkins
  • 9,803
  • 2
  • 21
  • 28
  • @mlocher Don't worry, I haven't abandoned Codeship. I'm just learning AWS. I've enjoyed Codeship and don't feel like it lacks in any of the ways that I use it. – Joe Hawkins Mar 07 '18 at 08:30
  • That's great to hear :) If that changes in the future don't hesitate to reach out, we're always happy to help and and love to hear from our users – mlocher Mar 08 '18 at 08:39

4 Answers4

17

A valid reason for not wanting to build a certain commit is when you use CodeBuild to generate a commit for you. For example, I have some code on the master branch which passes all the tests. I then want to update the changelog, package.json version and create a git tag on a new commit and push it back to the CodeCommit repo.

If I do this on Codebuild, the version-commit triggers another build! Given the contents of the commit does not materially change the behaviour of the code, there is no need to build & test this commit.

Besides all of this, Amazon should be looking at the features in the marketplace and attempting to provide at least feature-parity. Adding a RegEx check for "skip-ci" to the CodeBuild trigger-code would take a few hours to implement, at most.

uglow
  • 211
  • 2
  • 5
  • 2
    The reason this is the highest-voted, yet not really an answer is because devs are annoyed and frustrated that such a common-sense, obvious, and useful feature does not exist in CodePipeline. How could this not be a priority? Let me guess, CodePipeline team is rebuilding it from the ground up for the 10+ time because they can't communicate internally or don't want to look at the existing code. – Jarad Jul 20 '21 at 23:59
5

By default codepipeline creates a cloudwatch event which triggers your pipeline on all changes of the specific branch.

What you can do is to set this cloudwatch event to trigger a lambda function. This function can check whether it is necessary to build this commit and start your CodePipeline.

Here is an example of how to achieve this: https://aws.amazon.com/blogs/devops/adding-custom-logic-to-aws-codepipeline-with-aws-lambda-and-amazon-cloudwatch-events/

Here is a simple example for lambda function. It checks if the last commit has no [skip-CI] in its message and after that executes the pipeline. Keep in mind, that this code checks only the last commit if your change was a series of commits you might want to check everything between oldCommitId and commitId.

const AWS = require('aws-sdk');
const codecommit = new AWS.CodeCommit();
const codepipeline = new AWS.CodePipeline();

exports.handler = async (event) => {
    const { detail: { repositoryName, commitId, oldCommitId } } = event
    const { commit } = await codecommit.getCommit({
      commitId,
      repositoryName
    }).promise()

    if(commit.message.search(/\[skip-CI\]/) === -1) {
        const { pipelineExecutionId } = await codepipeline.startPipelineExecution({
            name: 'your-pipeline-name'
        }).promise()
        console.log(`Pipeline have started. Execution id: ${pipelineExecutionId}!`)        
    } else {
        console.log('Pipeline execution is not required')
    }
    return;
};
AlpacaGoesCrazy
  • 796
  • 8
  • 14
0
  • This isn't a feature offered by CodePipeline at this time.
  • I'd be curious to know why you view some builds as unnecessary. Do you push a sequence of commits and only want a build against the last commit? This may be more applicable in a team environment, but I would tend to want a build for every commit so I don't find myself in a situation where I push code and pick up and build someone else's broken code for the first time in my build.
Aaron
  • 1,575
  • 10
  • 18
  • In theory, I agree with what you're saying. But in my question I mention that I am working alone on a project. Some commits are strictly for code cleanup, and I don't want to waste build minutes on CodePipeline on such changes. – Joe Hawkins Mar 07 '18 at 21:39
  • Well, there may be situations, wherein you just updated the documentation or merely a README, which do not need a build. I think it is an important feature which can be used to prevent time consuming builds on mere document updates. – Monis Nov 11 '19 at 13:44
  • a good example are build processes that do commits. like a maven release process. part of it is, to modify the pom.xml to update the version number. this triggers an endless cycle. other build tools therefore have the option to omit triggered builds/trigegrs – Hendrik Jander Nov 24 '20 at 11:00
  • my use case for that is to deploy codepipeline differently for different branch. Some of builds are not required for feature branch. But I'd like to use one pipeline.yml file to make it easy to maintain since most of them are common. – Joey Yi Zhao Dec 02 '20 at 00:23
-5

I would suggest a manual review stage in your pipeline before it builds. Then you can just approve it when you are ready to build.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135