Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow per PR/branch deployment #1086

Open
braska opened this issue Aug 18, 2024 · 1 comment
Open

Allow per PR/branch deployment #1086

braska opened this issue Aug 18, 2024 · 1 comment

Comments

@braska
Copy link

braska commented Aug 18, 2024

I want to have ability to do isolated deployments per PR/branch. Every such deployment should be done to the same account.

When I try to describe such PR/branch deployment pipeline with CDK, there is no way to use ${{ github.ref_name }} or ${{ github.event.pull_request.number }} in stage name.

Ideally, I would like to pass stageName while calling .addStage(...) and make it dependent on variables that will be later accessible in Github Workflow during execution.

Is there any trick that would allow me to do per PR/branch deployments?

@jcuffe
Copy link

jcuffe commented Sep 14, 2024

@braska I think you could accomplish this by patching the generated workflow file to add a top-level environment variable set to your chosen value, and then referencing that variable in your stage definition:

declare const pipeline = gh.GitHubWorkflow;

pipeline.workflowFile.patch(
  gh.JsonPatch.add('/env', { STAGE_ID: '${{ github.ref_name }}' }),
);

const stageId = process.env.STAGE_ID || 'IdUsedInLocalDevEnvironment'
pipeline.addStage(new MyStage(this, stageId, { env: ENV }));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants