How to use Azure Artifacts with dotnet in Jenkins pipeline?

You probably want to have one PAT (Personal Access Token) for Azure DevOps in Jenkins Credentials and use it not only for getting source code from GIT, but also for getting NuGet packages for build, right?

So, you need the withCredentials construct with an environment variable VSS_NUGET_EXTERNAL_FEED_ENDPOINTS to be used like this:

steps {
  script {
    withCredentials(bindings: [usernamePassword(credentialsId: '...', passwordVariable: 'PAT', usernameVariable: 'PAT_USERNAME')]) {
      env.VSS_NUGET_EXTERNAL_FEED_ENDPOINTS = "{\"endpointCredentials\": [{\"endpoint\":\"\", \"username\":\"build\", \"password\":\"${PAT}\"}]}"
      sh "dotnet ..."

This greatly simplifies Jenkins CI solution with Azure DevOps, because now you have to monitor much less possible expirations.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: