本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
以下步骤已使用提供的 Docker 镜像中列出的操作系统进行了测试。 CodeBuild
使用 IAM 角色设置权限
使用中的 NuGet 软件包时,需要执行这些步骤 CodeBuild。 CodeArtifact
登录 AWS Management Console 并打开 IAM 控制台,网址为https://console.aws.amazon.com/iam/
。 -
在导航窗格中,选择角色。在角色页面上,编辑您的 CodeBuild 构建项目使用的角色。此角色必须具有以下权限。
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "codeartifact:GetAuthorizationToken", "codeartifact:GetRepositoryEndpoint", "codeartifact:ReadFromRepository" ], "Resource": "*" }, { "Effect": "Allow", "Action": "sts:GetServiceBearerToken", "Resource": "*", "Condition": { "StringEquals": { "sts:AWSServiceName": "codeartifact.amazonaws.com" } } } ] }
重要
如果您还 CodeBuild 想使用发布软件包,请添加
codeartifact:PublishPackageVersion
权限。有关信息,请参阅《IAM 用户指南》中的修改角色。
消费 NuGet 包裹
要使用来自的 NuGet 软件包 CodeBuild,请在项目buildspec.yaml
文件中包含以下内容。
install
在本节中,安装 CodeArtifact 凭据提供程序以配置命令行工具,例如msbuild
和dotnet
以生成和发布软件包。 CodeArtifact在该
pre-build
部分中,将您的 CodeArtifact 存储库添加到您的 NuGet 配置中。
请见以下 buildspec.yaml
示例。有关更多信息,请参阅 CodeArtifact 与一起使用 NuGet。
安装凭证提供程序并添加存储库源后,您可以运行该build
部分中的 NuGet CLI 工具命令来使用 NuGet 软件包。
Linux
要使用 NuGet 包裹,请使用dotnet
以下方法:
version: 0.2
phases:
install:
runtime-versions:
dotnet: latest
commands:
- export PATH="$PATH:/root/.dotnet/tools"
- dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
- dotnet codeartifact-creds install
pre_build:
commands:
- dotnet nuget add source -n codeartifact $(aws codeartifact get-repository-endpoint --domain my_domain
--domain-owner 111122223333
--repository my_repo
--format nuget --query repositoryEndpoint --output text)"v3/index.json"
build:
commands:
- dotnet add package <packageName> --source codeartifact
Windows
要使用 NuGet 包裹,请使用dotnet
以下方法:
version: 0.2
phases:
install:
commands:
- dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
- dotnet codeartifact-creds install
pre_build:
commands:
- dotnet nuget add source -n codeartifact "$(aws codeartifact get-repository-endpoint --domain my_domain
--domain-owner 111122223333
--repository my_repo
--format nuget --query repositoryEndpoint --output text)v3/index.json"
build:
commands:
- dotnet add package <packageName> --source codeartifact
使用 NuGet 软件包构建
要使用来自的 NuGet 包进行构建 CodeBuild,请在项目buildspec.yaml
文件中包含以下内容。
install
在本节中,安装 CodeArtifact 凭据提供程序以配置命令行工具,例如msbuild
和dotnet
以生成和发布软件包。 CodeArtifact在该
pre-build
部分中,将您的 CodeArtifact 存储库添加到您的 NuGet 配置中。
请见以下 buildspec.yaml
示例。有关更多信息,请参阅 CodeArtifact 与一起使用 NuGet。
安装凭证提供程序并添加存储库源后,您可以运行 NuGet CLI 工具命令,如build
本节dotnet build
所示。
Linux
要使用dotnet
以下方法构建 NuGet 软件包:
version: 0.2
phases:
install:
runtime-versions:
dotnet: latest
commands:
- export PATH="$PATH:/root/.dotnet/tools"
- dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
- dotnet codeartifact-creds install
pre_build:
commands:
- dotnet nuget add source -n codeartifact $(aws codeartifact get-repository-endpoint --domain my_domain --domain-owner 111122223333 --repository my_repo --format nuget --query repositoryEndpoint --output text)"v3/index.json"
build:
commands:
- dotnet build
要使用msbuild
以下方法构建 NuGet 软件包:
version: 0.2
phases:
install:
runtime-versions:
dotnet: latest
commands:
- export PATH="$PATH:/root/.dotnet/tools"
- dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
- dotnet codeartifact-creds install
pre_build:
commands:
- dotnet nuget add source -n codeartifact $(aws codeartifact get-repository-endpoint --domain my_domain
--domain-owner 111122223333
--repository my_repo
--format nuget --query repositoryEndpoint --output text)"v3/index.json"
build:
commands:
- msbuild -t:Rebuild -p:Configuration=Release
Windows
要使用dotnet
以下方法构建 NuGet 软件包:
version: 0.2
phases:
install:
commands:
- dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
- dotnet codeartifact-creds install
pre_build:
commands:
- dotnet nuget add source -n codeartifact "$(aws codeartifact get-repository-endpoint --domain my_domain
--domain-owner 111122223333
--repository my_repo
--format nuget --query repositoryEndpoint --output text)v3/index.json"
build:
commands:
- dotnet build
要使用msbuild
以下方法构建 NuGet 软件包:
version: 0.2
phases:
install:
commands:
- dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
- dotnet codeartifact-creds install
pre_build:
commands:
- dotnet nuget add source -n codeartifact "$(aws codeartifact get-repository-endpoint --domain my_domain
--domain-owner 111122223333
--repository my_repo
--format nuget --query repositoryEndpoint --output text)v3/index.json"
build:
commands:
- msbuild -t:Rebuild -p:Configuration=Release
发布 NuGet 软件包
要从中发布 NuGet 包 CodeBuild,请在项目buildspec.yaml
文件中包含以下内容。
install
在本节中,安装 CodeArtifact 凭据提供程序以配置命令行工具,例如msbuild
和dotnet
以生成和发布软件包。 CodeArtifact在该
pre-build
部分中,将您的 CodeArtifact 存储库添加到您的 NuGet 配置中。
请见以下 buildspec.yaml
示例。有关更多信息,请参阅 CodeArtifact 与一起使用 NuGet。
安装凭证提供程序并添加存储库源后,您可以运行该build
部分中的 NuGet CLI 工具命令并发布您的 NuGet 软件包。
Linux
要使用dotnet
以下方法发布 NuGet 软件包:
version: 0.2
phases:
install:
runtime-versions:
dotnet: latest
commands:
- export PATH="$PATH:/root/.dotnet/tools"
- dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
- dotnet codeartifact-creds install
pre_build:
commands:
- dotnet nuget add source -n codeartifact $(aws codeartifact get-repository-endpoint --domain my_domain
--domain-owner 111122223333
--repository my_repo
--format nuget --query repositoryEndpoint --output text)"v3/index.json"
build:
commands:
- dotnet pack -o .
- dotnet nuget push *.nupkg -s codeartifact
Windows
要使用dotnet
以下方法发布 NuGet 软件包:
version: 0.2
phases:
install:
commands:
- dotnet tool install -g AWS.CodeArtifact.NuGet.CredentialProvider
- dotnet codeartifact-creds install
pre_build:
commands:
- dotnet nuget add source -n codeartifact "$(aws codeartifact get-repository-endpoint --domain my_domain
--domain-owner 111122223333
--repository my_repo
--format nuget --query repositoryEndpoint --output text)v3/index.json"
build:
commands:
- dotnet pack -o .
- dotnet nuget push *.nupkg -s codeartifact