Skip to content

Can i have AWS Codepipeline that starts only manually?

0

I want to have a pipeline with source from codecommit repo that will be idle all the time, and start manually from a chosen commit. I want to have a script with cli command that will execute pipeline from commit using commit hash id. Can it be done

3 Answers
4

Hi, Lets say you have an existing pipeline which gets triggered automatically on every push. To stop the automatic triggers, you will have to find a cloudwatch event rule that is associated with the pipeline. You can disable that rule to stop automatic triggers.

If you want to start the pipeline on a specific commit id, you can use the following command using awscli

aws codepipeline start-pipeline-execution \
    --name <pipeline-name> \
    --client-request-token <unique-token> \
    --source-revision revisions='[{"actionName":"<source-stage-action-name>","revisionId":"<commit-id>"}]'

Here you can specify the name of Source stage in source-stage-action-name and that would trigger the entire pipeline(not just source stage) Make sure before you run the the command, awscli has required permissions. Below are the list of permissions that might be required: codepipeline:StartPipelineExecution

If the code is hosted on codecommit:

codecommit:GetCommit
codecommit:GetBranch
codecommit:GitPull

If the code is hosted on Github:

codepipeline:PollForSourceChanges
codepipeline:RetryStageExecution

There might be more permissions needed so please make sure the awscli has the required permissions

AWS
answered a year ago
0

Hello, yes this can be done, by implementing the following:

  • Create a CodePipeline with a CodeCommit source stage.
  • Set the PollForSourceChanges parameter to false to prevent automatic triggering.
  • Remove any CloudWatch Events rules that might trigger the pipeline automatically.

You can then use the AWS CLI to manually start the pipeline from a specific commit. Here's an example BASH script:

#!/bin/bash

# Replace these variables with your actual values
PIPELINE_NAME="YourPipelineName"
REPOSITORY_NAME="YourRepositoryName"
BRANCH_NAME="YourBranchName"

# Function to start the pipeline execution
start_pipeline_execution() {
    local commit_id=$1
    
    aws codepipeline start-pipeline-execution \
        --name $PIPELINE_NAME \
        --client-request-token $(date +%s) \
        --source-revision "{\"type\": \"CodeCommit\", \"revisionType\": \"String\", \"revisionValue\": \"$commit_id\"}"
}

# Check if commit ID is provided
if [ $# -eq 0 ]; then
    echo "Please provide a commit ID"
    exit 1
fi

COMMIT_ID=$1

# Start the pipeline execution
start_pipeline_execution $COMMIT_ID

echo "Pipeline execution started for commit: $COMMIT_ID"

Ensure your AWS CLI is configured with the necessary permissions to start pipeline executions. The IAM role associated with your pipeline must have permissions to access the specified commit in the CodeCommit repository. You may need to adjust the region in the AWS CLI command if your pipeline is not in the default region.

AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.