1

UPDATED POST

I have written a script to create a CICD pipeline:

trigger:
- feature/pipeline
 
stages:
- stage: Build
  displayName: 'Build and Test'
  jobs:
  - job: GoBuildJob
    pool:
      name: "Default"
      demands:
        - Agent.Name -equals Ubuntu-ESXI_VM_Build
    steps:
    - task: GoTool@0
      inputs:
        version: '1.20'
      displayName: 'Installing Go'
 
    - script: |
        go mod init son-pipeline
        go mod tidy
      displayName: 'Initialize and Tidy Dependencies'
 
    - script: go build -o $(Build.BinariesDirectory)/myproject
      displayName: 'Building Go Project'
      workingDirectory: '$(System.DefaultWorkingDirectory)/myproject'
 
    - script: go test -v ./...
      displayName: 'Run Unit Tests'

    - script: |
        cd $(Build.SourcesDirectory)/myproject
        npm install
        npm run build
      displayName: 'Build Go project'
 
    # Copy the Go binary to the staging directory
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(Build.BinariesDirectory)'
        Contents: 'myproject'
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
      displayName: 'Copy Built Binary to Staging Directory'
 
    # Copy the package.json file to the staging directory
    - task: CopyFiles@2
      inputs:
        SourceFolder: '$(Build.SourcesDirectory)/myproject'  # Path to your project directory
        Contents: 'package.json'
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
      displayName: 'Copy package.json to Staging Directory'
 
    # Authenticate with the npm registry
    # - task: npmAuthenticate@0
    #   inputs:
    #     workingFile: 'myproject/.npmrc'  # Path to the .npmrc file
 
    # # Publish the npm package to Azure Artifacts
    # - script: |
    #     cd $(Build.ArtifactStagingDirectory)
    #     npm publish --registry=<ORG>/IP_CAL_SON/_packaging/SON-FEED/npm/registry/
    #   displayName: 'Publish npm Package to Azure Artifacts'
    - task: Npm@1
      inputs:
        command: 'publish'
        workingDir: '$(Build.SourcesDirectory)/myproject'
        publishRegistry: 'useFeed'
        publishFeed: '<FEEDid>' 

- stage: Deploy
  displayName: 'Deploy to Production'
  jobs:
  - job: DeployToProduction
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/feature/pipeline'))
    pool:
      name: "Default"
      demands:
        - Agent.Name -equals Ubuntu-ESXI_VM_Build
    steps:
    - script: echo "Deploying to production environment"
      displayName: 'Deploy to Production - Placeholder'

Now what I want to do is I want to use Azure Artifacts for storing binaries. My target machine is Linux VM 24.04. Also how to write the CD part for this? I am new to this. I have looked in the official documentation but can't understand most things.

UPDATE

I have updated the code and I have followed this: https://learn.microsoft.com/en-us/azure/devops/artifacts/npm/npmrc?view=azure-devops&tabs=windows%2Cclassic

But at last I am getting SSL certificate error.

UPDATE-2

The logs are:

    Starting: Npm
==============================================================================
Task         : npm
Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version      : 1.180.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
/home/cicd/.nvm/versions/node/v23.9.0/bin/npm --version
11.2.0
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
/home/cicd/.nvm/versions/node/v23.9.0/bin/npm config list
; "user" config from /home/cicd/myagent/_work/22/npm/2618.npmrc

//<ORG-link>/<FEEDid>/_packaging/b4025a17-a917-7a1f-b006-efe86260fa90/npm/registry/:_authToken = (protected)
registry = "<ORG-link>/***/_packaging/***/npm/registry/"

; "env" config from environment

userconfig = "/home/cicd/myagent/_work/22/npm/2618.npmrc"

; node bin location = /home/cicd/.nvm/versions/node/v23.9.0/bin/node
; node version = v23.9.0
; npm local prefix = /home/cicd/myagent/_work/22/s/myproject
; npm version = 11.2.0
; cwd = /home/cicd/myagent/_work/22/s/myproject
; HOME = /home/cicd
; Run `npm config ls -l` to show all defaults.
/home/cicd/.nvm/versions/node/v23.9.0/bin/npm publish
npm notice
npm notice 📦  [email protected]
npm notice Tarball Contents
npm notice 1.8MB main
npm notice 78B main.go
npm notice 229B package.json
npm notice Tarball Details
npm notice name: myproject
npm notice version: 1.0.0
npm notice filename: myproject-1.0.0.tgz
npm notice package size: 1.1 MB
npm notice unpacked size: 1.8 MB
npm notice shasum: dfa3f492f0625e5291d1313abb9d26719e4044b6
npm notice integrity: sha512-i5aLWxQ7Z55K3[...]oSmGoGXa7KfDw==
npm notice total files: 3
npm notice
npm notice Publishing to https://<ORG-link>/***/_packaging/***/npm/registry/ with tag latest and default access
npm error code UNABLE_TO_VERIFY_LEAF_SIGNATURE
npm error errno UNABLE_TO_VERIFY_LEAF_SIGNATURE
npm error request to https://<ORG-link>/***/_packaging/***/npm/registry/myproject failed, reason: unable to verify the first certificate
npm error A complete log of this run can be found in: /home/cicd/.npm/_logs/2025-03-12T07_13_23_246Z-debug-0.log
##[warning]Couldn't find a debug log in the cache or working directory
##[error]Error: Npm failed with return code: 1
Finishing: Npm

UPDATE-3

package.json

{
  "name": "myproject",
  "version": "1.0.0",
  "description": "Hello go",
  "main": "main",
  "scripts": {
    "build": "go build -o main"
  },
  "keywords": [],
  "author": "Pritam",
  "license": "ISC",
  "type": "commonjs"
}

UPDATE-4

Logs of failed pipeline:

2025-03-12T07:13:21.7923275Z ##[section]Starting: Npm
2025-03-12T07:13:21.7926746Z ==============================================================================
2025-03-12T07:13:21.7926837Z Task         : npm
2025-03-12T07:13:21.7926890Z Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
2025-03-12T07:13:21.7927005Z Version      : 1.180.0
2025-03-12T07:13:21.7927052Z Author       : Microsoft Corporation
2025-03-12T07:13:21.7927105Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/npm
2025-03-12T07:13:21.7927183Z ==============================================================================
2025-03-12T07:13:22.1261581Z [command]/home/cicd/.nvm/versions/node/v23.9.0/bin/npm --version
2025-03-12T07:13:22.2267972Z 11.2.0
2025-03-12T07:13:22.2325310Z SYSTEMVSSCONNECTION exists true
2025-03-12T07:13:22.7707096Z SYSTEMVSSCONNECTION exists true
2025-03-12T07:13:22.8022360Z SYSTEMVSSCONNECTION exists true
2025-03-12T07:13:22.8480602Z SYSTEMVSSCONNECTION exists true
2025-03-12T07:13:23.0770633Z [command]/home/cicd/.nvm/versions/node/v23.9.0/bin/npm config list
2025-03-12T07:13:23.1921628Z ; "user" config from /home/cicd/myagent/_work/22/npm/2618.npmrc
2025-03-12T07:13:23.1921768Z 
2025-03-12T07:13:23.1922297Z <org-link>/<project-id>/_packaging/<feed-id>/npm/registry/:_authToken = (protected)
2025-03-12T07:13:23.1922557Z registry = "https://<org-link>/***/_packaging/***/npm/registry/"
2025-03-12T07:13:23.1922652Z 
2025-03-12T07:13:23.1922748Z ; "env" config from environment
2025-03-12T07:13:23.1922800Z 
2025-03-12T07:13:23.1922923Z userconfig = "/home/cicd/myagent/_work/22/npm/2618.npmrc"
2025-03-12T07:13:23.1922990Z 
2025-03-12T07:13:23.1923128Z ; node bin location = /home/cicd/.nvm/versions/node/v23.9.0/bin/node
2025-03-12T07:13:23.1923272Z ; node version = v23.9.0
2025-03-12T07:13:23.1923397Z ; npm local prefix = /home/cicd/myagent/_work/22/s/myproject
2025-03-12T07:13:23.1923539Z ; npm version = 11.2.0
2025-03-12T07:13:23.1923654Z ; cwd = /home/cicd/myagent/_work/22/s/myproject
2025-03-12T07:13:23.1923769Z ; HOME = /home/cicd
2025-03-12T07:13:23.1923952Z ; Run `npm config ls -l` to show all defaults.
2025-03-12T07:13:23.1929653Z [command]/home/cicd/.nvm/versions/node/v23.9.0/bin/npm publish
2025-03-12T07:15:43.9402674Z npm notice
2025-03-12T07:15:43.9403412Z npm notice 📦  [email protected]
2025-03-12T07:15:43.9403560Z npm notice Tarball Contents
2025-03-12T07:15:43.9408438Z npm notice 1.8MB main
2025-03-12T07:15:43.9408862Z npm notice 78B main.go
2025-03-12T07:15:43.9408996Z npm notice 229B package.json
2025-03-12T07:15:43.9409128Z npm notice Tarball Details
2025-03-12T07:15:43.9409341Z npm notice name: myproject
2025-03-12T07:15:43.9411646Z npm notice version: 1.0.0
2025-03-12T07:15:43.9411928Z npm notice filename: myproject-1.0.0.tgz
2025-03-12T07:15:43.9412067Z npm notice package size: 1.1 MB
2025-03-12T07:15:43.9412194Z npm notice unpacked size: 1.8 MB
2025-03-12T07:15:43.9412326Z npm notice shasum: dfa3f492f0625e5291d1313abb9d26719e4044b6
2025-03-12T07:15:43.9412567Z npm notice integrity: sha512-i5aLWxQ7Z55K3[...]oSmGoGXa7KfDw==
2025-03-12T07:15:43.9412697Z npm notice total files: 3
2025-03-12T07:15:43.9412805Z npm notice
2025-03-12T07:15:43.9412975Z npm notice Publishing to https://<org-link>/***/_packaging/***/npm/registry/ with tag latest and default access
2025-03-12T07:15:43.9413176Z npm error code UNABLE_TO_VERIFY_LEAF_SIGNATURE
2025-03-12T07:15:43.9413312Z npm error errno UNABLE_TO_VERIFY_LEAF_SIGNATURE
2025-03-12T07:15:43.9413517Z npm error request to https://<org-link>/***/_packaging/***/npm/registry/myproject failed, reason: unable to verify the first certificate
2025-03-12T07:15:43.9414276Z npm error A complete log of this run can be found in: /home/cicd/.npm/_logs/2025-03-12T07_13_23_246Z-debug-0.log
2025-03-12T07:15:43.9710955Z ##[warning]Couldn't find a debug log in the cache or working directory
2025-03-12T07:15:43.9718662Z ##[error]Error: Npm failed with return code: 1
2025-03-12T07:15:43.9720658Z ##[section]Finishing: Npm

3 Answers 3

0

I should download your artifacts from the build stage on the deploy stage: DownloadBuildArtifacts@1

- task: DownloadBuildArtifacts@1
  inputs:
    buildType: 'current'
    downloadType: 'single'
    artifactName: 'Go-Binary-Artifact'
    downloadPath: '$(System.ArtifactsDirectory)'

Then use $(System.ArtifactsDirectory) as a source of your binaries.

Sign up to request clarification or add additional context in comments.

3 Comments

Shouldn't I use the Artifacts feed in this case?
@HeyHello No, you download the build results that were published by PublishBuildArtifacts@1 task. Artifacts feed you use if you need to share your build results with other projects. In the case of single project, you create a build artifact by PublishBuildArtifacts@1 and download by DownloadBuildArtifacts@1: Publish and download build artifacts
I am asked to use Azure Artifacts for storing binaries.
0

You may use UniversalPackages@0 Publish and download Universal Packages with Azure Pipelines

- task: UniversalPackages@0
  displayName: 'Universal publish'
  inputs:
    command: publish
    vstsFeedPublish: 'project/feed-name'
    vstsFeedPackagePublish: package-name
    publishDirectory: '$(Build.ArtifactStagingDirectory)'

- task: UniversalPackages@0
  displayName: 'Universal download'
  inputs:
    command: download
    vstsFeed: 'project/feed-name''
    vstsFeedPackage: package-name
    vstsPackageVersion: '*'
    vstsFeedPackagePublish: testpg

5 Comments

Not working. ##[error]Failed to get artifact tool. Universal Packages are not supported in Azure DevOps Server.
@HeyHello ... yes, it is for services... in this case, you may consider using npm approach: Get started with NuGet packages in Azure Artifacts. or use standard build artifacts without a feed.
You can see my updated code
@HeyHello, Provide the detailed logs of the failed steps in the pipeline?
Updated the logs in update 2
0

If you want to pass the binary file output by the "go build" command from the GoBuildJob job to the subsequent DeployToProduction job for use, it is recommended using the Publish Pipeline Artifacts task and Download Pipeline Artifacts task:

  • In the GoBuildJob job, you can use the Publish Pipeline Artifacts task to publish the binary file as a Pipeline artifact.
  • In the subsequent DeployToProduction job, you can use the Download Pipeline Artifacts task to download the artifact published by the previous job.

See below sample as reference.

. . .

stages:
- stage: Build
  displayName: 'Build and Test'
  jobs:
  - job: GoBuildJob
    . . .
    steps:
    . . .

    - script: go build -o $(Build.BinariesDirectory)/myproject
      displayName: 'Building Go Project'
      workingDirectory: '$(System.DefaultWorkingDirectory)/myproject'
    
    - task: PublishPipelineArtifact@1
      displayName: 'Publish Pipeline Artifact'
      inputs:
        targetPath: '$(Build.BinariesDirectory)'
        artifact: 'goBin'

- stage: Deploy
  displayName: 'Deploy to Production'
  dependsOn: Build
  jobs:
  - job: DeployToProduction
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/feature/pipeline'))
    . . .
    steps:
    - task: DownloadPipelineArtifact@2
      displayName: 'Download Pipeline Artifact'
      inputs:
        artifactName: 'goBin'
        targetPath: '$(System.DefaultWorkingDirectory)/bin'

If you want to publish the binary file as a package to an Azure Artifacts feed, as far as I know, there is no method to directly publish the Go binary file as an npm package to Azure Artifacts. Instead, you can publish the Go binary file as an Universal Package to an Azure Artifacts feed.

Universal Packages allow you bundle various types of files into a single Universal Package.


UPDATE:

To store the binary files of Go project to an Azure Artifacts feed, as suggested above, you can publish the binary files as an Universal Package.

See below example as reference:

. . .

variables:
  package_version: '1.0.1'

stages:
- stage: Build
  jobs:
  - job: GoBuild
    displayName: 'Build and Test'
    . . .
    steps:
    . . .
    
    - task: Go@0
      displayName: 'Build Go Project'
      inputs:
        command: 'build'
        arguments: '-o $(Build.BinariesDirectory)/myproject'
        workingDirectory: '$(System.DefaultWorkingDirectory)/myproject'
    
    - task: Go@0
      displayName: 'Run Unit Tests'
      inputs:
        command: 'test'
        arguments: '-v ./...'
    
    - task: PublishPipelineArtifact@1
      displayName: 'Publish Pipeline Artifact'
      inputs:
        targetPath: '$(Build.BinariesDirectory)'
        artifact: 'BinFiles'

- stage: Deploy
  dependsOn: Build
  jobs:
  - job: Publish
    displayName: 'Publish to Azure Artifacts'
    . . .
    steps:
    - checkout: none
    
    # Download the Pipeline Artifact (binary files of the Go project)
    # into the folder '$(System.DefaultWorkingDirectory)/myBinFiles'.
    - task: DownloadPipelineArtifact@2
      displayName: 'Download Pipeline Artifact'
      inputs:
        buildType: 'current'
        artifactName: 'BinFiles'
        targetPath: '$(System.DefaultWorkingDirectory)/myBinFiles'
      
      # Publish the binary files as an Universal Package
      # from the folder '$(System.DefaultWorkingDirectory)/myBinFiles' to the Azure Artifacts feed.
    - task: UniversalPackages@0
      displayName: 'Publish Universal Package'
      inputs:
        command: 'publish'
        publishDirectory: '$(System.DefaultWorkingDirectory)/myBinFiles'
        feedsToUsePublish: 'internal'
        vstsFeedPublish: 'ProjDemo/myProjFeed'  # If a project-scope feed, provide '{project-name}/{feed-name}'. If organization-scope, provide '{feed-name}'.
        vstsFeedPackagePublish: 'go_myproject'  # A custom name of the package. you can set it to be same as your Go project name, but cannot use uppercase.
        versionOption: 'custom'
        versionPublish: '$(package_version)'

enter image description here


UPDATE_2:

If you are using Azure DevOps Server which does not support Universal Packages, as a workaround, you can try go-npm (or golang-npm):

  1. You need to upload/publish the binary files of your Go project to a 3rd-party file server, such as GitHub Releases, Amazon S3, etc...

  2. Initialize and configure a npm package with go-npm that is able to download the binary files of Go project from the file server.

  3. Publish the npm package to Azure Artifacts feed on your Azure DevOps Server.

  4. When you run "npm install" command to install the npm package from the Azure Artifacts feed, it will download the binary files of Go project from the file server.

Note:

Essentially, this method does not directly store the binary files of Go project in Azure Artifacts, instead, the binary files are stored in a 3rd-party file server from where you can download the binary files via go-npm.

30 Comments

Thing is that Universal package is not working. It was showing some error. SO I switched to this one.
@HeyHello, What is your purpose? Pass the binary file between jobs, or publish the binary file as a package to Azure Artifacts feed?
use Azure Artifacts for storing binaries. I think the later one
@HeyHello, I have shared an example to show how to publish the binary files of Go project as an Universal Package to the Azure Artifacts feed. See UPDATE.
I am using ADO server and it works only for ADO service. ##[error]Failed to get artifact tool. Universal Packages are not supported in Azure DevOps Server.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.