Azure Artifacts gives unauthorized when trying to build Dockerfile
I am using Azure DevOps Pipelines to create a Docker image from my github repo. It is having issue however accessing the nuget package that I have hosted in Azure Artifacts. It returns unauthorized (401). As Azure Pipelines seems to be relativly new, there does not seem to be much help, and the help that is out there that is not specifically for Artifacts has not worked for me.
azure-pipelines.yml
pool:
vmImage: 'Ubuntu 16.04'
variables:
imageName: 'dockerRepoName:$(build.buildId)'
steps:
- script: docker build -f dockerRepoName -t $(imageName) .
displayName: 'docker build'
Dockerfile
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY MyWebsite.Website/MyWebsite.Website.csproj MyWebsite.Website/
COPY NuGet.config ./
RUN dotnet restore MyWebsite.Website/MyWebsite.Website.csproj
COPY . .
WORKDIR /src/MyWebsite.Website
RUN dotnet build MyWebsite.Website.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish MyWebsite.Website.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyWebsite.Website.dll"]
Nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="http_proxy" value="https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json" />
<add key="http_proxy.user" value="notSureWhatUserGoesHere_TriedABunchOfDifferentOnes" />
<add key="http_proxy.password" value="PersonalAccessTOkenFromAzureDevops" />
</config>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="MyWebsite" value="https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json" />
</packageSources>
</configuration>
Took out the actual user and passwords, so that obviously was not what I used for those. The urls are also updated to "companyName" since it a private repo so the url will not work.
Build Error
2018-11-21T19:21:00.0200396Z Restoring packages for /src/MyWebsite.Website/MyWebsite.Website.csproj...
2018-11-21T19:21:00.6762563Z /usr/share/dotnet/sdk/2.1.500/NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json. [/src/MyWebsite.Website/MyWebsite.Website.csproj]
2018-11-21T19:21:00.6763038Z /usr/share/dotnet/sdk/2.1.500/NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [/src/MyWebsite.Website/MyWebsite.Website.csproj]
2018-11-21T19:21:01.0956272Z The command '/bin/sh -c dotnet restore MyWebsite.Website/MyWebsite.Website.csproj' returned a non-zero code: 1
2018-11-21T19:21:01.1105851Z ##[error]Bash exited with code '1'.
2018-11-21T19:21:01.1192131Z ##[section]Finishing: docker build
azure docker nuget azure-devops
add a comment |
I am using Azure DevOps Pipelines to create a Docker image from my github repo. It is having issue however accessing the nuget package that I have hosted in Azure Artifacts. It returns unauthorized (401). As Azure Pipelines seems to be relativly new, there does not seem to be much help, and the help that is out there that is not specifically for Artifacts has not worked for me.
azure-pipelines.yml
pool:
vmImage: 'Ubuntu 16.04'
variables:
imageName: 'dockerRepoName:$(build.buildId)'
steps:
- script: docker build -f dockerRepoName -t $(imageName) .
displayName: 'docker build'
Dockerfile
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY MyWebsite.Website/MyWebsite.Website.csproj MyWebsite.Website/
COPY NuGet.config ./
RUN dotnet restore MyWebsite.Website/MyWebsite.Website.csproj
COPY . .
WORKDIR /src/MyWebsite.Website
RUN dotnet build MyWebsite.Website.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish MyWebsite.Website.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyWebsite.Website.dll"]
Nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="http_proxy" value="https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json" />
<add key="http_proxy.user" value="notSureWhatUserGoesHere_TriedABunchOfDifferentOnes" />
<add key="http_proxy.password" value="PersonalAccessTOkenFromAzureDevops" />
</config>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="MyWebsite" value="https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json" />
</packageSources>
</configuration>
Took out the actual user and passwords, so that obviously was not what I used for those. The urls are also updated to "companyName" since it a private repo so the url will not work.
Build Error
2018-11-21T19:21:00.0200396Z Restoring packages for /src/MyWebsite.Website/MyWebsite.Website.csproj...
2018-11-21T19:21:00.6762563Z /usr/share/dotnet/sdk/2.1.500/NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json. [/src/MyWebsite.Website/MyWebsite.Website.csproj]
2018-11-21T19:21:00.6763038Z /usr/share/dotnet/sdk/2.1.500/NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [/src/MyWebsite.Website/MyWebsite.Website.csproj]
2018-11-21T19:21:01.0956272Z The command '/bin/sh -c dotnet restore MyWebsite.Website/MyWebsite.Website.csproj' returned a non-zero code: 1
2018-11-21T19:21:01.1105851Z ##[error]Bash exited with code '1'.
2018-11-21T19:21:01.1192131Z ##[section]Finishing: docker build
azure docker nuget azure-devops
add a comment |
I am using Azure DevOps Pipelines to create a Docker image from my github repo. It is having issue however accessing the nuget package that I have hosted in Azure Artifacts. It returns unauthorized (401). As Azure Pipelines seems to be relativly new, there does not seem to be much help, and the help that is out there that is not specifically for Artifacts has not worked for me.
azure-pipelines.yml
pool:
vmImage: 'Ubuntu 16.04'
variables:
imageName: 'dockerRepoName:$(build.buildId)'
steps:
- script: docker build -f dockerRepoName -t $(imageName) .
displayName: 'docker build'
Dockerfile
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY MyWebsite.Website/MyWebsite.Website.csproj MyWebsite.Website/
COPY NuGet.config ./
RUN dotnet restore MyWebsite.Website/MyWebsite.Website.csproj
COPY . .
WORKDIR /src/MyWebsite.Website
RUN dotnet build MyWebsite.Website.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish MyWebsite.Website.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyWebsite.Website.dll"]
Nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="http_proxy" value="https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json" />
<add key="http_proxy.user" value="notSureWhatUserGoesHere_TriedABunchOfDifferentOnes" />
<add key="http_proxy.password" value="PersonalAccessTOkenFromAzureDevops" />
</config>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="MyWebsite" value="https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json" />
</packageSources>
</configuration>
Took out the actual user and passwords, so that obviously was not what I used for those. The urls are also updated to "companyName" since it a private repo so the url will not work.
Build Error
2018-11-21T19:21:00.0200396Z Restoring packages for /src/MyWebsite.Website/MyWebsite.Website.csproj...
2018-11-21T19:21:00.6762563Z /usr/share/dotnet/sdk/2.1.500/NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json. [/src/MyWebsite.Website/MyWebsite.Website.csproj]
2018-11-21T19:21:00.6763038Z /usr/share/dotnet/sdk/2.1.500/NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [/src/MyWebsite.Website/MyWebsite.Website.csproj]
2018-11-21T19:21:01.0956272Z The command '/bin/sh -c dotnet restore MyWebsite.Website/MyWebsite.Website.csproj' returned a non-zero code: 1
2018-11-21T19:21:01.1105851Z ##[error]Bash exited with code '1'.
2018-11-21T19:21:01.1192131Z ##[section]Finishing: docker build
azure docker nuget azure-devops
I am using Azure DevOps Pipelines to create a Docker image from my github repo. It is having issue however accessing the nuget package that I have hosted in Azure Artifacts. It returns unauthorized (401). As Azure Pipelines seems to be relativly new, there does not seem to be much help, and the help that is out there that is not specifically for Artifacts has not worked for me.
azure-pipelines.yml
pool:
vmImage: 'Ubuntu 16.04'
variables:
imageName: 'dockerRepoName:$(build.buildId)'
steps:
- script: docker build -f dockerRepoName -t $(imageName) .
displayName: 'docker build'
Dockerfile
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY MyWebsite.Website/MyWebsite.Website.csproj MyWebsite.Website/
COPY NuGet.config ./
RUN dotnet restore MyWebsite.Website/MyWebsite.Website.csproj
COPY . .
WORKDIR /src/MyWebsite.Website
RUN dotnet build MyWebsite.Website.csproj -c Release -o /app
FROM build AS publish
RUN dotnet publish MyWebsite.Website.csproj -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyWebsite.Website.dll"]
Nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="http_proxy" value="https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json" />
<add key="http_proxy.user" value="notSureWhatUserGoesHere_TriedABunchOfDifferentOnes" />
<add key="http_proxy.password" value="PersonalAccessTOkenFromAzureDevops" />
</config>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="MyWebsite" value="https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json" />
</packageSources>
</configuration>
Took out the actual user and passwords, so that obviously was not what I used for those. The urls are also updated to "companyName" since it a private repo so the url will not work.
Build Error
2018-11-21T19:21:00.0200396Z Restoring packages for /src/MyWebsite.Website/MyWebsite.Website.csproj...
2018-11-21T19:21:00.6762563Z /usr/share/dotnet/sdk/2.1.500/NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/companyName/_packaging/MyWebsite.Api/nuget/v3/index.json. [/src/MyWebsite.Website/MyWebsite.Website.csproj]
2018-11-21T19:21:00.6763038Z /usr/share/dotnet/sdk/2.1.500/NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [/src/MyWebsite.Website/MyWebsite.Website.csproj]
2018-11-21T19:21:01.0956272Z The command '/bin/sh -c dotnet restore MyWebsite.Website/MyWebsite.Website.csproj' returned a non-zero code: 1
2018-11-21T19:21:01.1105851Z ##[error]Bash exited with code '1'.
2018-11-21T19:21:01.1192131Z ##[section]Finishing: docker build
azure docker nuget azure-devops
azure docker nuget azure-devops
edited Nov 22 '18 at 9:48
Charles Xu
3,383127
3,383127
asked Nov 21 '18 at 19:46
Brandon TurpyBrandon Turpy
393119
393119
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
- Create a Personal Access Token (PAT)
- Grant Read access to the Package section of the Scopes
- Modify the dockerfile
- Specify the
PAT
build argument asdocker build --build-arg PAT="{access token}"
Example Docker file
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
# The Personal Access token required to access the artifacts
ARG PAT
# Install the Credential Provider to configure the access
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
# Configure the environment variables
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{"endpointCredentials": [{"endpoint":"{package source}/index.json", "password":"${PAT}"}]}"
WORKDIR /src
COPY ["src/Sample/Sample.csproj", "src/Sample/"]
RUN dotnet restore -s "{package source}/index.json" "src/Sample/Sample.csproj"
COPY . .
WORKDIR "/src/src/Sample"
RUN dotnet build "Sample.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Sample.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Sample.dll"]
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419491%2fazure-artifacts-gives-unauthorized-when-trying-to-build-dockerfile%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- Create a Personal Access Token (PAT)
- Grant Read access to the Package section of the Scopes
- Modify the dockerfile
- Specify the
PAT
build argument asdocker build --build-arg PAT="{access token}"
Example Docker file
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
# The Personal Access token required to access the artifacts
ARG PAT
# Install the Credential Provider to configure the access
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
# Configure the environment variables
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{"endpointCredentials": [{"endpoint":"{package source}/index.json", "password":"${PAT}"}]}"
WORKDIR /src
COPY ["src/Sample/Sample.csproj", "src/Sample/"]
RUN dotnet restore -s "{package source}/index.json" "src/Sample/Sample.csproj"
COPY . .
WORKDIR "/src/src/Sample"
RUN dotnet build "Sample.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Sample.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Sample.dll"]
add a comment |
- Create a Personal Access Token (PAT)
- Grant Read access to the Package section of the Scopes
- Modify the dockerfile
- Specify the
PAT
build argument asdocker build --build-arg PAT="{access token}"
Example Docker file
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
# The Personal Access token required to access the artifacts
ARG PAT
# Install the Credential Provider to configure the access
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
# Configure the environment variables
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{"endpointCredentials": [{"endpoint":"{package source}/index.json", "password":"${PAT}"}]}"
WORKDIR /src
COPY ["src/Sample/Sample.csproj", "src/Sample/"]
RUN dotnet restore -s "{package source}/index.json" "src/Sample/Sample.csproj"
COPY . .
WORKDIR "/src/src/Sample"
RUN dotnet build "Sample.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Sample.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Sample.dll"]
add a comment |
- Create a Personal Access Token (PAT)
- Grant Read access to the Package section of the Scopes
- Modify the dockerfile
- Specify the
PAT
build argument asdocker build --build-arg PAT="{access token}"
Example Docker file
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
# The Personal Access token required to access the artifacts
ARG PAT
# Install the Credential Provider to configure the access
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
# Configure the environment variables
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{"endpointCredentials": [{"endpoint":"{package source}/index.json", "password":"${PAT}"}]}"
WORKDIR /src
COPY ["src/Sample/Sample.csproj", "src/Sample/"]
RUN dotnet restore -s "{package source}/index.json" "src/Sample/Sample.csproj"
COPY . .
WORKDIR "/src/src/Sample"
RUN dotnet build "Sample.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Sample.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Sample.dll"]
- Create a Personal Access Token (PAT)
- Grant Read access to the Package section of the Scopes
- Modify the dockerfile
- Specify the
PAT
build argument asdocker build --build-arg PAT="{access token}"
Example Docker file
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
# The Personal Access token required to access the artifacts
ARG PAT
# Install the Credential Provider to configure the access
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
# Configure the environment variables
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{"endpointCredentials": [{"endpoint":"{package source}/index.json", "password":"${PAT}"}]}"
WORKDIR /src
COPY ["src/Sample/Sample.csproj", "src/Sample/"]
RUN dotnet restore -s "{package source}/index.json" "src/Sample/Sample.csproj"
COPY . .
WORKDIR "/src/src/Sample"
RUN dotnet build "Sample.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Sample.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Sample.dll"]
edited Nov 28 '18 at 2:05
answered Nov 28 '18 at 1:56
GeoffGeoff
125210
125210
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419491%2fazure-artifacts-gives-unauthorized-when-trying-to-build-dockerfile%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown