-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(codepipeline): Pipeline Variables #5604
Conversation
Submitted for early feedback. Still missing: updating the ReadMe files. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
* | ||
* @see https://docs.aws.amazon.com/codepipeline/latest/APIReference/API_PutJobSuccessResult.html | ||
*/ | ||
public variable(variableName: string): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might confuse people why this class has both variable
and variableExpression
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variableExpression
is protected, it's not part of the public API of the class, so I don't think that will be an issue.
packages/@aws-cdk/aws-codepipeline-actions/test/codecommit/test.codecommit-source-action.ts
Outdated
Show resolved
Hide resolved
* | ||
* @default - no variables will be emitted from this action | ||
*/ | ||
readonly variables?: CodeCommitSourceVariables; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be a boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my reply above.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
88ca213
to
1c96514
Compare
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
This is sort of a general question about validation expectations in cdk: Should this validate that the namespace given doesn't collide with an artifact name? When this happens, CloudFormation will catch it, throw an exception, and rollback etc, but seems like cdk should be proactive in validating this to fail faster. I did something similar and tested for it in https://github.com/aws/aws-cdk/pull/5326/files#diff-7cc3d22a6d7b4682f2c898e18e4e1e61R118, although you'd probably have a more elegant approach knowing the codebase. Obviously, this is mostly for the case where someone provides a namespace explicitly. |
Yep, that's a great point @jgondron! |
95de96b
to
e7aff40
Compare
Changed to have variables be read-only instance properties of the different action classes. @eladb , please re-review. Thanks! |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
throw new Error(`Cannot reference variables of action '${this.actionProperties.actionName}', ` + | ||
'as that action was never added to a pipeline'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making the variable expression a lazy value, just make the actual namespace a lazy value. This way you can get rid of the error-prone variableWasReferenced
method:
protected variableExpression(variableName: string): string {
this.variableReferenced = true;
return `#{${this.variablesNamespace}}.${variableName}`;
}
And then in the initializer:
this.variablesNamespace = actionProperties.variablesNamespace
?? Lazy.string({ produce: () => this.renderedNamespace });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this API even more error-prone? If you decide to cache the variables, like I did originally:
export class GitHubSourceAction extends Action {
constructor(props: GitHubSourceActionProps) {
// ...
this._variables = {
repositoryName: this.variableExpression('RepositoryName'),
branchName: this.variableExpression('BranchName'),
authorDate: this.variableExpression('AuthorDate'),
committerDate: this.variableExpression('CommitterDate'),
commitId: this.variableExpression('CommitId'),
commitMessage: this.variableExpression('CommitMessage'),
commitUrl: this.variableExpression('CommitUrl'),
};
}
, instead of returning them on demand from the variables
getter, you will always make variableReferenced
true
, even if no variables were actually referenced, and thus always render the namespace, even if it wasn't required.
packages/@aws-cdk/aws-codepipeline-actions/lib/codebuild/build-action.ts
Outdated
Show resolved
Hide resolved
packages/@aws-cdk/aws-codepipeline-actions/lib/codecommit/source-action.ts
Show resolved
Hide resolved
packages/@aws-cdk/aws-codepipeline-actions/lib/ecr/source-action.ts
Outdated
Show resolved
Hide resolved
e7aff40
to
bba4cdd
Compare
Changed to implement according to #5604 (comment). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Added support for the CodePipeline Variables feature, by adding action class-specific interfaces that represent the collection of variables they emit, and a readonly property of the action instance that returns that interface. Plus a class representing the global pipeline variables with static properties. Fixes aws#5219
bba4cdd
to
14b023b
Compare
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Changed the names as suggested, @eladb this is ready for another round of reviews. Thanks! |
Thank you for contributing! Your pull request is now being automatically merged. |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request is now being automatically merged. |
CloudFormationAction (and subclasses) still do not have a variable() method in cdk 2.22. |
Yes, it definitely is (I can't find the issue for it, but it is). |
Added support for the CodePipeline Variables feature, by adding action class-specific interfaces that represent the collection of variables they emit, and a readonly property of the action instance that returns that interface. Plus a class representing the global pipeline variables with static properties.
Fixes #5219
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license