Skip to content
v2.278.0

GitHubSourceActionProps Struct ​

Construction properties of the GitHubSourceAction GitHub source action.

Example ​

ts
// Read the secret from Secrets Manager
const pipeline = new codepipeline.Pipeline(this, 'MyPipeline');
const sourceOutput = new codepipeline.Artifact();
const sourceAction = new codepipeline_actions.GitHubSourceAction({
  actionName: 'GitHub_Source',
  owner: 'awslabs',
  repo: 'aws-cdk',
  oauthToken: SecretValue.secretsManager('my-github-token'),
  output: sourceOutput,
  branch: 'develop', // default: 'master'
});
pipeline.addStage({
  stageName: 'Source',
  actions: [sourceAction],
});
python
# Read the secret from Secrets Manager
pipeline = codepipeline.Pipeline(self, "MyPipeline")
source_output = codepipeline.Artifact()
source_action = codepipeline_actions.GitHubSourceAction(
    action_name="GitHub_Source",
    owner="awslabs",
    repo="aws-cdk",
    oauth_token=SecretValue.secrets_manager("my-github-token"),
    output=source_output,
    branch="develop"
)
pipeline.add_stage(
    stage_name="Source",
    actions=[source_action]
)
java
// Read the secret from Secrets Manager
Pipeline pipeline = new Pipeline(this, "MyPipeline");
Artifact sourceOutput = new Artifact();
GitHubSourceAction sourceAction = GitHubSourceAction.Builder.create()
        .actionName("GitHub_Source")
        .owner("awslabs")
        .repo("aws-cdk")
        .oauthToken(SecretValue.secretsManager("my-github-token"))
        .output(sourceOutput)
        .branch("develop")
        .build();
pipeline.addStage(StageOptions.builder()
        .stageName("Source")
        .actions(List.of(sourceAction))
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Read the secret from Secrets Manager
var pipeline = new Pipeline(this, "MyPipeline");
var sourceOutput = new Artifact();
var sourceAction = new GitHubSourceAction(new GitHubSourceActionProps {
    ActionName = "GitHub_Source",
    Owner = "awslabs",
    Repo = "aws-cdk",
    OauthToken = SecretValue.SecretsManager("my-github-token"),
    Output = sourceOutput,
    Branch = "develop"
});
pipeline.AddStage(new StageOptions {
    StageName = "Source",
    Actions = new [] { sourceAction }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Read the secret from Secrets Manager
pipeline := codepipeline.NewPipeline(this, jsii.String("MyPipeline"))
sourceOutput := codepipeline.NewArtifact()
sourceAction := codepipeline_actions.NewGitHubSourceAction(&GitHubSourceActionProps{
	ActionName: jsii.String("GitHub_Source"),
	Owner: jsii.String("awslabs"),
	Repo: jsii.String("aws-cdk"),
	OauthToken: awscdk.SecretValue_SecretsManager(jsii.String("my-github-token")),
	Output: sourceOutput,
	Branch: jsii.String("develop"),
})
pipeline.AddStage(&StageOptions{
	StageName: jsii.String("Source"),
	Actions: []IAction{
		sourceAction,
	},
})

Properties ​

actionNamestringaction_namestractionNameStringActionNamestringActionName*string required #
The physical, human-readable name of the Action.

Note that Action names must be unique within a single Stage.

branchoptionalstringbranchoptionalstrbranchoptionalStringBranchoptionalstringBranchoptional*string = "master" #
The branch to use.
oauthTokenSecretValueoauth_tokenSecretValueoauthTokenSecretValueOauthTokenSecretValueOauthTokenSecretValue required #
A GitHub OAuth token to use for authentication.
notes

It is recommended to use a Secrets Manager Secret to obtain the token:

const oauth = cdk.SecretValue.secretsManager('my-github-token'); new GitHubSourceAction(this, 'GitHubAction', { oauthToken: oauth, ... });

If you rotate the value in the Secret, you must also change at least one property of the CodePipeline to force CloudFormation to re-read the secret.

The GitHub Personal Access Token should have these scopes:

  • repo - to read the repository
  • admin:repo_hook - if you plan to use webhooks (true by default)
outputArtifactoutputArtifactoutputArtifactOutputArtifactOutputArtifact required #
ownerstringownerstrownerStringOwnerstringOwner*string required #
The GitHub account/user that owns the repo.
repostringrepostrrepoStringRepostringRepo*string required #
The name of the repo, without the username.
runOrderoptionalnumberrun_orderoptionalint | floatrunOrderoptionalNumberRunOrderoptionaldoubleRunOrderoptional*float64 = 1 #
The runOrder property for this Action.

RunOrder determines the relative order in which multiple Actions in the same Stage execute.

triggeroptionalGitHubTriggertriggeroptionalGitHubTriggertriggeroptionalGitHubTriggerTriggeroptionalGitHubTriggerTriggeroptionalGitHubTrigger = GitHubTrigger.WEBHOOK #
How AWS CodePipeline should be triggered.
notes

With the default value "WEBHOOK", a webhook is created in GitHub that triggers the action With "POLL", CodePipeline periodically checks the source for changes With "None", the action is not triggered through changes in the source

To use WEBHOOK, your GitHub Personal Access Token should have admin:repo_hook scope (in addition to the regular repo scope).

variablesNamespaceoptionalstringvariables_namespaceoptionalstrvariablesNamespaceoptionalStringVariablesNamespaceoptionalstringVariablesNamespaceoptional*string #
The name of the namespace to use for variables emitted by this action.

Default: a name will be generated, based on the stage and action names, if any of the action's variables were referenced - otherwise, no namespace will be set