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

Codepipeline: Error thrown when adding custom action #19994

Closed
charles-hay opened this issue Apr 20, 2022 · 2 comments
Closed

Codepipeline: Error thrown when adding custom action #19994

charles-hay opened this issue Apr 20, 2022 · 2 comments
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@charles-hay
Copy link

charles-hay commented Apr 20, 2022

Describe the bug

I get the following error when trying to add a custom action to a stage in a pipeline

jsii.errors.JSIIError: Expected object reference, got {"$jsii.struct":{"fqn":"aws-cdk-lib.aws_codepipeline.CfnPipeline.ActionDeclarationProperty","data":{"actionTypeId":{"$jsii.struct":{"fqn":"aws-cdk-lib.aws_codepipeline.CfnPipeline.ActionTypeIdProperty","data":{"category":"Test","owner":"Custom","provider":"DeviceFarm","version":"1.0.0"}}},"name":"DeviceFarmAction","configuration":null,"inputArtifacts":null,"namespace":null,"outputArtifacts":null,"region":null,"roleArn":null,"runOrder":3}}}

The code is as follows:

 self.cfn_device_project = CfnResource(
            self,
            "cfn_device_project",
            type="AWS::DeviceFarm::Project",
            properties={
                "Name": project_name,
            }
        )
        self.cfn_device_pool = CfnResource(
            self,
            "cfn_device_pool",
            type="AWS::DeviceFarm::DevicePool",
            properties={
              "Description" : "Device pool for testing. Created by application pipeline",
              "Name" : project_name,
              "ProjectArn" : self.cfn_device_project.get_att('resource.arn'),
            }
        )
        self.action_config_device_pool_arn = codepipeline.CfnCustomActionType.ConfigurationPropertiesProperty(
            key=False,
            name="DevicePoolArn",
            required=True,
            secret=False,
            description="The AWS Device Farm device pool ARN.",
            queryable=True,
            type="String"
        )
        self.action_config_project_id = codepipeline.CfnCustomActionType.ConfigurationPropertiesProperty(
            key=False,
            name="ProjectId",
            required=True,
            secret=False,
            description="The AWS Device Farm project ID.",
            type="String",
        )
        self.action_config_app_type = codepipeline.CfnCustomActionType.ConfigurationPropertiesProperty(
            key=False,
            name="AppType",
            required=True,
            secret=False,
            description="The type of application to test.",
            type="String",
        )
        self.action_config_test_type = codepipeline.CfnCustomActionType.ConfigurationPropertiesProperty(
            key=False,
            name="TestType",
            required=True,
            secret=False,
            description="The type of test to run during the AWS Device Farm test step. If you're using one of the "
                        "built-in Device Farm tests, choose the type of test configured in your Device Farm project. "
                        "If you aren't using one of the Device Farm built-in tests, in the Test file path, enter the "
                        "path of the test definition file. The path is relative to the root of the input artifact for "
                        "your test.",
            type="String",
        )
        self.action_config_app = codepipeline.CfnCustomActionType.ConfigurationPropertiesProperty(
            key=False,
            name="App",
            required=True,
            secret=False,
            description="The path of the compiled app package. "
                        "The path is relative to the root of the input artifact for your test.",
            type="String"
        )
        self.configuration_properties=[
                self.action_config_device_pool_arn,
                self.action_config_project_id,
                self.action_config_app_type,
                self.action_config_test_type,
                self.action_config_app,
            ]
        self.device_farm_action_type = codepipeline.CfnCustomActionType(
            self,
            "CustomDeviceFarmAction",
            category="Test",
            provider="DeviceFarm",
            version="1.0.0",
            input_artifact_details=codepipeline.CfnCustomActionType.ArtifactDetailsProperty(
                maximum_count=1,
                minimum_count=1
            ),
            output_artifact_details=codepipeline.CfnCustomActionType.ArtifactDetailsProperty(
                maximum_count=5,
                minimum_count=0,
            ),
            configuration_properties=self.configuration_properties
        )
        self.device_farm_action = codepipeline.CfnPipeline.ActionDeclarationProperty(
            action_type_id=codepipeline.CfnPipeline.ActionTypeIdProperty(
                category="Test",
                owner="Custom",
                provider="DeviceFarm",
                version="1.0.0"
            ),
            name="DeviceFarmAction",
            run_order=3,
            configuration={
                "DevicePoolArn": self.cfn_device_pool.get_att('resource.arn'),
                "ProjectId": self.cfn_device_project.get_att('id'),
                "AppType": "",
                "TestType": ""
            }
        )
        if qa_stage is None and qa_deployment_group is None:
            raise Exception("Either qa_stage or qa_deployment_group must be present")
        self.qa_stage = qa_stage or codepipeline.StageProps(
            stage_name="QA",
            actions=[
                codepipeline_actions.CodeDeployEcsDeployAction(
                    deployment_group=qa_deployment_group,  # type: ignore
                    app_spec_template_input=self._source_artifact,
                    action_name="Deploy",
                    task_definition_template_file=ArtifactPath(
                        self._source_artifact, "codedeploy/appspec.yml"
                    ),
                    run_order=1,
                ),
                codepipeline_actions.CodeBuildAction(
                    input=self._source_artifact,
                    project=codebuild.PipelineProject(
                        self,
                        "QAFunctionalTestProject",
                        build_spec=codebuild.BuildSpec.from_source_filename(
                            "codebuild/functional.buildspec.yml"
                        ),
                    ),
                    type=codepipeline_actions.CodeBuildActionType.TEST,
                    action_name="FunctionalTest",
                    run_order=2,
                ),
                codepipeline_actions.CodeBuildAction(
                    input=self._source_artifact,
                    project=codebuild.PipelineProject(
                        self,
                        "QAApiTestProject",
                        build_spec=codebuild.BuildSpec.from_source_filename(
                            "codebuild/api.buildspec.yml"
                        ),
                    ),
                    type=codepipeline_actions.CodeBuildActionType.TEST,
                    action_name="ApiTest",
                    run_order=2,
                ),
                self.device_farm_action,
            ],
        )

Expected Behavior

Successful addition of custom action to pipeline

Current Behavior

Error mentioned above thrown

Reproduction Steps

Run the code above in custom pipeline

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.20.0 (build 738ef49)

Framework Version

No response

Node.js Version

v16.14.2

OS

MacOs

Language

Python

Language Version

No response

Other information

No response

@charles-hay charles-hay added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 20, 2022
@github-actions github-actions bot added the @aws-cdk/aws-codepipeline Related to AWS CodePipeline label Apr 20, 2022
@ryparker ryparker added the p1 label Apr 26, 2022
@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Apr 27, 2022
@skinny85
Copy link
Contributor

skinny85 commented May 4, 2022

Hi @charles-hay,

thanks for opening the issue. The problem is that you're mixing two levels of resources that CDK supports.

The Cfn* classes that you're using are what CDK calls Layer 1 constructs. While the Stage and other classes without the Cfn* prefix that you're using are Layer 2 constructs. You can't really mix and match the two this way - you have to use one, or the other.

If you want to write a custom implementation of the IAction interface (which represents an Action in Layer 2), see this issue: #2516 (comment) for help.

Thanks,
Adam

@skinny85 skinny85 added guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed bug This issue is a bug. p1 labels May 4, 2022
@skinny85 skinny85 removed their assignment May 4, 2022
@github-actions
Copy link

github-actions bot commented May 6, 2022

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-codepipeline Related to AWS CodePipeline closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. guidance Question that needs advice or information. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

4 participants