Answers: <p>As of Sep 4 2018 Amazon added support for multiple input sources:</p>
  
  <p><a href="https://aws.amazon.com/about-aws/whats-new/2018/08/aws-codebuild-adds-ability-to-create-build-projects-with-multiple-input-sources-and-output-artifacts/" rel="nofollow noreferrer">https://aws.amazon.com/about-aws/whats-new/2018/08/aws-codebuild-adds-ability-to-create-build-projects-with-multiple-input-sources-and-output-artifacts/</a></p>
  
  <p>From <a href="https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html" rel="nofollow noreferrer">documentation</a>:</p>
  
  <pre><code>{
  "name": "sample-project",
  "source": {
    "type": "S3",
    "location": "bucket/sample.zip"
  },
  "secondarySources": [
    {
      "type": "CODECOMMIT",
      "location": "https://git-codecommit.us-west-2.amazonaws.com/v1/repos/repo"
      "sourceIdentifier": "source1"
    },
    {
      "type": "GITHUB",
      "location": "https://github.com/awslabs/aws-codebuild-jenkins-plugin"
      "sourceIdentifier": "source2"
    }
  ],
  </code></pre>
  
  <hr>
  
  <pre><code>version: 0.2
  
  phases:
    build:
      commands:
        - cd $CODEBUILD_SRC_DIR_source1
        - touch file1
        - cd $CODEBUILD_SRC_DIR_source2
        - touch file2
  
  artifacts:
    secondary-artifacts:
      artifact1:
        base-directory: $CODEBUILD_SRC_DIR_source1
        files:
          - file1
      artifact2:
        base-directory: $CODEBUILD_SRC_DIR_source2
        files:
          - file2
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2018-09-07T09:59:02.330Z
Answers: 2018-09-07T09:59:02.330Z
Answers: romaninsh
Answers: <p>We've had exactly the same problem - our build stage needs to use information from two separate locations.</p>
  
  <p>To solve this in a generic manner, I've created two general purpose Lambdas - one that will merge artifacts, and one that will extract specific files from an artifact. In both cases a new artifact is created that can be passed on to a subsequent CodePipeline stage.</p>
  
  <p>See <a href="https://github.com/tooltwist/codepipeline-artifact-munge" rel="noreferrer">https://github.com/tooltwist/codepipeline-artifact-munge</a></p>
  
  <p>If it does not meet your exact requirement, it should be easy enough to tweak to do what you need.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-01-26T13:55:27.250Z
Answers: Awesome work, Philip, thanks for sharing this Lambda.
Answers: romaninsh
Answers: CC BY-SA 3.0
Answers: 2018-01-08T18:19:17.450Z
Answers: 2018-01-08T18:19:17.450Z
Answers: Philip Callender
Answers: <p>I have actually solved the problem by cloning repository directly in codebuild:</p>
  
  <p>Pass GitHub token:</p>
  
  <pre><code>      - { Name: GITHUB_TOKEN, Value: {Ref: GitHubToken } }
        - { Name: GITHUB_BRANCH, Value: {Ref: GitHubBranch } }
  </code></pre>
  
  <p>#
  Execute git clone in install step:</p>
  
  <pre><code>      - git clone --single-branch --depth=1 -b $GITHUB_BRANCH https://gitorgname:$GITHUB_TOKEN@github.com/gitorgname/reponame.git  src/reponame
  </code></pre>
  
  <p>I found that this solution is easier to implement, does not rely on Lambdas and even though performs two pulls, works quite reliably.</p>
  
Answers: CC BY-SA 4.0
Answers: 2018-06-03T04:20:01.443Z
Answers: Where exactly do you put the - { Name ... } ?
Answers: Alex R
Answers: CC BY-SA 4.0
Answers: 2018-06-22T14:12:15.987Z
Answers: I create CodeBuild through cloudformation, but that is an environment variable which you can specify through console also.
Answers: romaninsh
Answers: CC BY-SA 3.0
Answers: 2018-01-26T13:51:39.543Z
Answers: 2018-01-26T15:06:55.530Z
Answers: 2018-01-26T15:06:55.530Z
Answers: romaninsh
Answers: <p>You can review CodeBuild. The BuildScpec file can be put in the CodeBuild project.<a href="https://i.sstatic.net/qaKxX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qaKxX.png" alt="CodeBuild Project"></a></p>
  
Answers: CC BY-SA 4.0
Answers: 2018-06-15T08:16:50.627Z
Answers: I fail to see how this answer the question.
Answers: Tensibai
Answers: CC BY-SA 4.0
Answers: 2018-06-15T05:35:48.753Z
Answers: 2018-06-15T05:35:48.753Z
Answers: darangom
Body: <p>I am building an AWS CodePipeline which depends on two source repositories. If the 'CodeBuild' step is specified with multiple Input artifacts, then you get the error: <code>.. declares 2 input artifacts which is more than the maximum count</code>. Documentation has a strict requirement for CodeBuild to have only a single input artifact.</p>
  
  <p>Lambdas, on another hand, do not have this limitation. I've been looking for a way how a Lambda could "merge" two artifacts into a single one which I can pass to the CodeBuild then. Unfortunately, information on this subject is quite limited. </p>
  
  <p>Does anyone have a working CodePipeline Lambda which would merge two Artifacts into one?</p>
  
  <p><a href="https://i.sstatic.net/togs2.png" rel="noreferrer"><img src="https://i.sstatic.net/togs2.png" alt="enter image description here"></a></p>
  
  <p><strong>Note</strong>: Documentation about <a href="http://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html#how-to-lambda-more-sample" rel="noreferrer">How to access artifacts</a>.</p>
  
Tags: <amazon-web-services><build-pipeline>
Title: CodeBuild - multiple input artifacts in AWS Pipeline
UserDisplayName: romaninsh
ThreadText: # CodeBuild - multiple input artifacts in AWS Pipeline
  
  (Asked by: username_0 on 2017-07-13)
  
  I am building an AWS CodePipeline which depends on two source repositories. If the 'CodeBuild' step is specified with multiple Input artifacts, then you get the error: `.. declares 2 input artifacts which is more than the maximum count`. Documentation has a strict requirement for CodeBuild to have only a single input artifact.
  
  Lambdas, on another hand, do not have this limitation. I've been looking for a way how a Lambda could "merge" two artifacts into a single one which I can pass to the CodeBuild then. Unfortunately, information on this subject is quite limited.
  
  Does anyone have a working CodePipeline Lambda which would merge two Artifacts into one?
  
  [![enter image description here](https://i.sstatic.net/togs2.png)](https://i.sstatic.net/togs2.png)
  
  **Note**: Documentation about [How to access artifacts](http://docs.aws.amazon.com/codepipeline/latest/userguide/actions-invoke-lambda-function.html#how-to-lambda-more-sample).
  
  **Tags:** amazon-web-services, build-pipeline
  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_0 on 2018-09-07. Score: 3 | Accepted answer
  
  As of Sep 4 2018 Amazon added support for multiple input sources:
  
  <https://aws.amazon.com/about-aws/whats-new/2018/08/aws-codebuild-adds-ability-to-create-build-projects-with-multiple-input-sources-and-output-artifacts/>
  
  From [documentation](https://docs.aws.amazon.com/codebuild/latest/userguide/sample-multi-in-out.html):
  
  ```
  {
  "name": "sample-project",
  "source": {
    "type": "S3",
    "location": "bucket/sample.zip"
  },
  "secondarySources": [
    {
      "type": "CODECOMMIT",
      "location": "https://git-codecommit.us-west-2.amazonaws.com/v1/repos/repo"
      "sourceIdentifier": "source1"
    },
    {
      "type": "GITHUB",
      "location": "https://github.com/awslabs/aws-codebuild-jenkins-plugin"
      "sourceIdentifier": "source2"
    }
  ],
  
  ```
  
  ---
  
  ```
  version: 0.2
  
  phases:
    build:
      commands:
        - cd $CODEBUILD_SRC_DIR_source1
        - touch file1
        - cd $CODEBUILD_SRC_DIR_source2
        - touch file2
  
  artifacts:
    secondary-artifacts:
      artifact1:
        base-directory: $CODEBUILD_SRC_DIR_source1
        files:
          - file1
      artifact2:
        base-directory: $CODEBUILD_SRC_DIR_source2
        files:
          - file2
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2018-01-08. Score: 6
  
  We've had exactly the same problem - our build stage needs to use information from two separate locations.
  
  To solve this in a generic manner, I've created two general purpose Lambdas - one that will merge artifacts, and one that will extract specific files from an artifact. In both cases a new artifact is created that can be passed on to a subsequent CodePipeline stage.
  
  See <https://github.com/tooltwist/codepipeline-artifact-munge>
  
  If it does not meet your exact requirement, it should be easy enough to tweak to do what you need.
  
  > **Comments:**
  > **username_0**: Awesome work, username_1, thanks for sharing this Lambda.  
  
  ---
  
  ### Answer by username_0 on 2018-01-26. Score: 4
  
  I have actually solved the problem by cloning repository directly in codebuild:
  
  Pass GitHub token:
  
  ```
        - { Name: GITHUB_TOKEN, Value: {Ref: GitHubToken } }
        - { Name: GITHUB_BRANCH, Value: {Ref: GitHubBranch } }
  
  ```
  
  #
  Execute git clone in install step:
  
  ```
        - git clone --single-branch --depth=1 -b $GITHUB_BRANCH https://gitorgname:$GITHUB_TOKEN@github.com/gitorgname/reponame.git  src/reponame
  
  ```
  
  I found that this solution is easier to implement, does not rely on Lambdas and even though performs two pulls, works quite reliably.
  
  > **Comments:**
  > **username_2**: Where exactly do you put the - { Name ... } ?  
  > **username_0**: I create CodeBuild through cloudformation, but that is an environment variable which you can specify through console also.  
  
  ---
  
  ### Answer by username_3 on 2018-06-15. Score: -1
  
  You can review CodeBuild. The BuildScpec file can be put in the CodeBuild project.[![CodeBuild Project](https://i.sstatic.net/qaKxX.png)](https://i.sstatic.net/qaKxX.png)
  
  > **Comments:**
  > **username_4**: I fail to see how this answer the question.  
  
  ---
  
  