LoginSignup
0
1

More than 3 years have passed since last update.

AWS CodeBuildのビルド成果物をCodeArtifactにMavenで登録する

Posted at

目的

CodeCommit上のJavaソースをCodeBuildでビルドして生成されたjarをCodeArtifactに登録します。CodeCommit、CodeBuildおよびCodeArtifactは設定済とします。

ソース

buildspec.yml
pom.xml
settings.xml
src

buildspec.yml

version: 0.2

phases:
  install: {}
  pre_build:
    commands:
    - export CODEARTIFACT_TOKEN=$(aws codeartifact get-authorization-token --domain ${CODEARTIFACT_DOMAIN} --domain-owner ${CODEARTIFACT_DOMAIN_OWNER} --query authorizationToken --output text)
  build:
    commands:
    - cp settings.xml ~/.m2/
    - mvn deploy
  post_build: {}

pom.xml

  <distributionManagement>
    <repository>
      <id>codeartifact</id>
      <url>${env.CODEARTIFACT_URL}</url>
    </repository>
  </distributionManagement>

settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <servers>
    <server>
      <id>codeartifact</id>
        <username>aws</username>
        <password>${env.CODEARTIFACT_TOKEN}</password>
      </server>
    </servers>
</settings>

CodeBuild

環境変数をビルドプロジェクトに設定します。

変数
CODEARTIFACT_DOMAIN CodeArtifactリポジトリ名
CODEARTIFACT_DOMAIN_OWNER CodeArtifactドメインオーナー
CODEARTIFACT_URL CodeArtifactリポジトリURL

これでビルドを実行するとCodeArtifactに登録されます。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1