title: AWS CDK Pipelines using with an existing codepipeline
body: <p>The documentation of @aws-cdk/pipelines seems to suggest that a CDK pipeline can be added to an existing @aws-cdk/aws-codepipeline/Pipeline, using the <code>codePipeline</code> prop: <a href="https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_pipelines.CodePipeline.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_pipelines.CodePipeline.html</a></p>
  <blockquote>
  <p><code>codePipeline?    Pipeline    An existing Pipeline to be reused and built upon.</code></p>
  </blockquote>
  <p>However, I am not able to get this to work and am experiencing multiple errors at the <code>cdk synth</code> step, depending on how I try to set it up. As far as I can tell there isn't really any documentation yet to cover this scenario.</p>
  <p>Essentially, we are trying to create a pipeline that runs something like:</p>
  <ul>
  <li>clone</li>
  <li>lint / typecheck / unit test</li>
  <li>cdk deploy to test environment</li>
  <li>integration tests</li>
  <li>deploy to preprod</li>
  <li>smoke test</li>
  <li>manual approval</li>
  <li>deploy to prod</li>
  </ul>
  <p>I guess it's just not clear the difference between this codebuild pipeline and the cdk pipeline. Also, the naming convention of stages seems a little unclear - referencing this issue: <a href="https://github.com/aws/aws-cdk/issues/15945" rel="nofollow noreferrer">https://github.com/aws/aws-cdk/issues/15945</a></p>
  <p>See: <a href="https://github.com/ChrisSargent/cdk-issues/blob/pipelines/lib/cdk-test-stack.ts" rel="nofollow noreferrer">https://github.com/ChrisSargent/cdk-issues/blob/pipelines/lib/cdk-test-stack.ts</a> and below:</p>
  <pre class="lang-js prettyprint-override"><code>import * as cdk from &quot;@aws-cdk/core&quot;;
  import * as pipelines from &quot;@aws-cdk/pipelines&quot;;
  import * as codepipeline from &quot;@aws-cdk/aws-codepipeline&quot;;
  import * as codepipeline_actions from &quot;@aws-cdk/aws-codepipeline-actions&quot;;
  
  export class CdkTestStack extends cdk.Stack {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
      super(scope, id, props);
  
      const cdkInput = pipelines.CodePipelineSource.gitHub(
        &quot;ChrisSargent/cdk-issues&quot;,
        &quot;pipelines&quot;
      );
  
      // Setup the code source action
      const sourceOutput = new codepipeline.Artifact();
      const sourceAction = new codepipeline_actions.GitHubSourceAction({
        owner: &quot;ChrisSargent&quot;,
        repo: &quot;cdk-issues&quot;,
        branch: &quot;pipelines&quot;,
        actionName: &quot;SourceAction&quot;,
        output: sourceOutput,
        oauthToken: cdk.SecretValue.secretsManager(&quot;git/ChrisSargent&quot;),
      });
  
      const pipeline = new codepipeline.Pipeline(this, &quot;Pipeline&quot;, {
        stages: [
          {
            actions: [sourceAction],
            stageName: &quot;GitSource&quot;,
          },
        ],
      });
  
      const cdkPipeline = new pipelines.CodePipeline(this, &quot;CDKPipeline&quot;, {
        codePipeline: pipeline,
        synth: new pipelines.ShellStep(&quot;Synth&quot;, {
          // Without input, we get: Error: CodeBuild action 'Synth' requires an input (and the pipeline doesn't have a Source to fall back to). Add an input or a pipeline source.
          // With input, we get:Error: Validation failed with the following errors: Source actions may only occur in first stage
          input: cdkInput,
          commands: [&quot;yarn install --frozen-lockfile&quot;, &quot;npx cdk synth&quot;],
        }),
      });
  
      // Produces: Stage 'PreProd' must have at least one action
      // pipeline.addStage(new MyApplication(this, &quot;PreProd&quot;));
  
      // Produces: The given Stage construct ('CdkTestStack/PreProd') should contain at least one Stack
      cdkPipeline.addStage(new MyApplication(this, &quot;PreProd&quot;));
    }
  }
  
  class MyApplication extends cdk.Stage {
    constructor(scope: cdk.Construct, id: string, props?: cdk.StageProps) {
      super(scope, id, props);
  
      console.log(&quot;Nothing to deploy&quot;);
    }
  }
  </code></pre>
  <p>Any guidance or experience with this would be much appreciated.</p>