I am creating a pipeline on Azure devOps to deploy an angular application. Inside the project dependencies there is a library published on the artifact of another project (under the same organization). How to configure my yaml file so that only that library is installed from the artifact registry?
This is my yaml file
pool:
name: Azure Pipelines
steps:
- task: NodeTool#0
displayName: 'Use Node 14.x'
inputs:
versionSpec: 14.x
- task: Npm#1
displayName: 'npm install angular-cli'
inputs:
command: custom
verbose: false
customCommand: 'install -g #angular/cli#12.1.1'
- **TASK TO INSTALL MY LIBRARY FROM ARTIFACT**
- task: Npm#1
displayName: 'npm install'
inputs:
verbose: false
- task: Npm#1
displayName: 'create build'
inputs:
command: custom
verbose: false
customCommand: 'run build'
- ...task to deploy
You can set the Artifact feed containing your required npm packages as upstream sources for the current project Artifact feed. To add upstream sources to your feed you can refer to Configure upstream sources.
Then you can add the packages you need to the dependencies of your package.json. And use npm task to install the packages.
Related
I have a build pipeline that publishes a release artifact for consumption by the release pipeline.
pool:
name: Azure Pipelines
demands:
- npm
- msbuild
steps:
- task: Cache#2
displayName: 'npm Cache'
inputs:
key: 'npm | "$(Agent.OS)" | $(System.DefaultWorkingDirectory)/ABCDashboard/Angular/package-lock.json'
path: '$(System.DefaultWorkingDirectory)/ABCDashboard/Angular/node_modules'
cacheHitVar: 'CACHE_RESTORED'
restoreKeys: 'npm | "$(Agent.OS)"'
- task: Npm#1
displayName: 'npm ci'
inputs:
command: ci
workingDir: ABCDashboard/Angular
verbose: false
condition: eq(variables['CACHE_RESTORED'],False)
- task: Npm#1
displayName: 'npm custom: angular build'
inputs:
command: custom
workingDir: ABCDashboard/Angular
verbose: false
customCommand: 'run-script build -- --prod'
- task: NuGetCommand#2
displayName: 'NuGet restore'
- task: MSBuild#1
displayName: '.Net build | Build solution (No need to build test as well)'
inputs:
solution: 'ABCDashboard/*.csproj'
msbuildArchitecture: x64
configuration: Release
msbuildArguments: '/p:OutputPath=$(Build.ArtifactStagingDirectory)'
clean: true
- task: Snyk.snyk-security-scan.custom-build-release-task.SnykSecurityScan#0
displayName: 'Snyk scan for open source vulnerabilities'
inputs:
serviceConnectionEndpoint: SnykAuthFreeTier
failOnIssues: false
testDirectory: ABCDashboard
additionalArguments: '-d --all-projects'
- task: CopyFiles#2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)/_PublishedWebsites/ABCDashboard'
inputs:
SourceFolder: ABCDashboard
Contents: |
Bundles/**
!(packages.config|phantomjs-license.txt)
TargetFolder: '$(Build.ArtifactStagingDirectory)/_PublishedWebsites/ABCDashboard'
- script: |
cd $(Build.ArtifactStagingDirectory)/_PublishedWebsites/ABCDashboard
ls -ltr
displayName: 'List artifacts under $(Build.ArtifactStagingDirectory)/_PublishedWebsites/ABCDashboard'
enabled: false
- task: CopyFiles#2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)/Release'
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)/_PublishedWebsites/ABCDashboard'
Contents: |
assets/**
bin/**
Bundles/**
Content/**
Scripts/**
Views/**
Web.config
Web.Dev.config
Web.Test.config
Web.Prod.config
Web.Beta.config
Web.Sandbox.config
ApplicationInsights.config
*.asax
*.ico
*.txt
TargetFolder: '$(Build.ArtifactStagingDirectory)/Release'
- task: ArchiveFiles#2
displayName: 'Archive $(Build.ArtifactStagingDirectory)/Release'
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/Release'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/Release/$(Build.BuildId).zip'
verbose: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: Release'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/Release'
ArtifactName: Release
I am looking into Azure Devops Artifacts, and from what I understand, we can create feeds to store those published build artifacts?
From my understanding, those kind of build artifacts my pipeline publishes are considered "Universal Packages"? and If so, I would have to add a Universal Package task like so in order for the build artifact (e.g. Release) to be stored in the Artifacts feed?
- task: UniversalPackages#0
displayName: 'Universal publish'
inputs:
command: publish
vstsFeedPublish: 'feedname'
vstsFeedPackagePublish: test
versionOption: custom
versionPublish: 1.1.0
I had already gone ahead and created a feed, do I just wait for next time I run a pipeline for a Release artifact to show up in the feed? or do I have to add "upstream sources" first? If upstream sources is a required step, I selected "Azure Artifacts feed in this organization" as the upstream source type and then when going over the configuration setting, for some reason, it's complaining that "This feed has no available views to be used as an upstream source" despite defined views as shown here:
Based on your requirement, you can use feed to store Build artifacts.
From my understanding, those kind of build artifacts my pipeline publishes are considered "Universal Packages"?
Your understanding is correct. You can use Universal Package Publish task to upload the build artifacts to Azure Feed.
Do i just wait for next time I run a pipeline for a Release artifact to show up in the feed? or do i have to add "upstream sources" first?
You don't need to add upstream sources for the feed.
To publish the Universal Package, you can directly use Universal Package Publish task in Pipeline.
For example:
- task: UniversalPackages#0
displayName: 'Universal publish'
inputs:
command: publish
vstsFeedPublish: 'name'
vstsFeedPackagePublish: kevintest
Result:
To use the published Universal Package, you can directly use Universal Package download task.
For example:
- task: UniversalPackages#0
displayName: 'Universal download'
inputs:
command: download
vstsFeed: 'name'
vstsFeedPackage: 'name'
vstsPackageVersion: 0.0.1
I am setting up an Azure Build pipeline to automatically build when a NuGet package get's published. In that build definition - I want to install the latest version of the package.
According to this answer, I need to restore packages first to authenticate against Dev Ops feeds.
I have set-up a build.yml file to include these tasks:
- task: DotNetCoreCLI#2
displayName: 'Restore Packages'
inputs:
command: restore
projects: web/*.csproj
vstsFeed: organizational-packages
- task: DotNetCoreCLI#2
displayName: Install Custom Internal Package Package
inputs:
command: 'custom'
custom: 'add'
arguments: 'package Custom.Internal.Package --prerelease'
projects: 'Web/*.csproj'
feedsToUse: 'select'
feedRestore: 'organizational-packages'
The NuGet feed is hosted in Azure Dev ops and has organizational scope.
When I go to run the build - the Azure Package feed is not included in the search for the package:
info : Adding PackageReference for package 'Custom.Internal.Package' into project
'/home/vsts/work/1/s/Project.Web/Web.csproj'.
info : GET https://api.nuget.org/v3/registration5-gz-semver2/custom.internal.package/index.json
info : NotFound https://api.nuget.org/v3/registration5-gz-semver2/cbh.surescripts.business/index.json 202ms
error: There are no versions available for the package 'Custom.Internal.Package'.
The package is located at https://myorg.pkgs.visualstudio.com/_packaging/organizational-packages/nuget/v3/index.json
I even tried accomplishing this with just the command line tasks:
- task: NuGetAuthenticate#0
displayName: Authenticate NuGet Feed
- task: CmdLine#2
displayName: Add Organizational Package Source
inputs:
script: 'dotnet nuget add source https://myorg.pkgs.visualstudio.com/_packaging/organizational-packages/nuget/v3/index.json -n credible'
- task: CmdLine#2
displayName: Install Custom Internal Package
inputs:
script: 'dotnet add package Custom.Internal.Package--prerelease'
workingDirectory: '$(Build.SourcesDirectory)/Web'
In the later case the package source is added - but I am getting an unauthorized error:
info : Adding PackageReference for package 'Custom.Internal.Package' into project '/home/vsts/work/1/s/Project.Web/Web.csproj'.
info : GET https://api.nuget.org/v3/registration5-gz-semver2/custom.internal.package/index.json
info : NotFound https://api.nuget.org/v3/registration5-gz-semver2/custom.internal.package/index.json 64ms
error: Unable to load the service index for source https://myorg.pkgs.visualstudio.com/_packaging/organziational-packages/nuget/v3/index.json.
error: Response status code does not indicate success: 401 (Unauthorized).
There is no feedsToUse in custom command in DotNetCoreCLI task, you could remove it, and try to add -v|--version <VERSION> to version the package:
- task: DotNetCoreCLI#2
displayName: 'dotnet custom'
inputs:
command: custom
projects: 'Web/*.csproj'
custom: add
arguments: 'package Custom.Internal.Package --prerelease -v 1.0.0'
I have a node.js/typescript/angular project in BitBucket that I want to create a build (CI) pipeline for it on Azure Devops. I used the classic editor to create the pipeline (reason below) and am trying to add the following task(s)/step(s):
npm install #types/node#8.10.52
ng build (ng is angular)
If was to use the YAML configuration, the resulting YAML file looks like the following file below, so how do i create a "script" manually after the Node task i have in classic editor? I only have options to add "npm" as a task, which is why i have added 3 npm tasks as shown in image above with 3 separate custom commands to mimic the steps configuration in the YML file below. Is that the way to do it with custom command?
YAML file npm/angular representation via YAML configuration:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
- script: |
npm install -g #angular/cli
npm install
ng build --prod
displayName: 'npm install and build'
Reason why Im using classic editor:
When i tried saving the YAML configuration pipeline, i got a "Error from bitbucket: something went wrong" error, which appears to be a write-permission issue based on what i found from Atlassian forums.
So i ended up just using the classic pipeline editor, and this way i was able to select a specific branch (i.e. dev) instead of master (prod) branch.
The way I've handled this is to add a script to your package.json:
"scripts": {
"ng": "ng",
"build": "ng build",
"build-prod": "ng build --configuration=production"
"build-dev": "ng build --configuration=dev"
},
...
Then, you just call run-script from the custom NPM task:
Or you could optionally on the task just call run-script build --prod since you can pass arguments on the task.
These same steps are available in YAML, it would look something like this:
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.x'
displayName: 'Install node.js'
- task: Npm#1
inputs:
command: 'install'
displayName: npm install
- task: Npm#1
inputs:
command: 'custom'
customCommand: 'run-script build --prod'
displayName: 'npm build'
I am struggling to get a simple build and deploy working and was hoping for some assistance. Could anyone review the steps and also why the Publish Artifacts does not work? It's a simple Angular 7 project.
Error:
[section]Starting: Publish Artifact: dist
========================================================================== Task: Publish Build Artifacts Description: Publish build
artifacts to Azure Pipelines/TFS or a file share Version:
1.142.2 Author : Microsoft Corporation Help : More Information
[warning]Directory 'D:\a\1\s\dist' is empty. Nothing will be added to build artifact 'dist'.
[section]Finishing: Publish Artifact: dist
YAML:
pool:
vmImage: Hosted VS2017
demands: npm
steps:
- script: |
echo Write your commands here
mkdir dist
echo Use the environment variables input below to pass secret variables to this script
displayName: 'Command - mkdir dist'
- task: Npm#1
displayName: 'npm install'
inputs:
verbose: false
- task: Npm#1
displayName: 'npm build'
inputs:
command: custom
verbose: false
customCommand: 'build --prod'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: dist'
inputs:
PathtoPublish: dist
ArtifactName: dist
- task: FtpUpload#1
displayName: 'FTP Upload: dist'
inputs:
credentialsOption: inputs
serverUrl: ‘xxx’
username: Tester2
password: 'Tester$2'
rootDirectory: dist
filePatterns: '*'
remoteDirectory: /
trustSSL: true
Azure DevOps Pipeline issue
The Publish Build Artifacts task is used to publish build artifacts to Azure Pipelines, TFS, or a file share.
But, just like Daniel and Andrey said, although you add the npm build, you did not set the installed folder to be dist. So the result of npm build will not be saved in the dist folder. In this case, the folder dist is empty.
Besides, to save the build result to the dist folder, you can try to use the option -- -op like following:
run ng build --prod -- -op ..\..\dist
The ..\..\dist should use relative path based on the project.json file.
Check the document JavaScript frameworks: AngularJS for some more details info.
Hope this helps.
I have a build configuration defined here:
https://github.com/cpoDesign/APIFramework/blob/master/azure-pipelines.yml
I have managed to generate a nuget package using the following command
- task: DotNetCoreCLI#2
inputs:
command: pack
projects: '**/*ApiFramework.csproj'
A subset of the task output of the script is
Task "PackTask"
2018-11-27T23:02:32.4459067Z Successfully created package '/home/vsts/work/1/a/CPODesign.ApiFramework.1.0.0.nupkg'.
Next step resolved:
I do not want to create a build with release into nuget as those steps have to be logically separated. Therefore I have created a new step Create a drop.
Configuration:
My drop task definition:
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
contents: '**/$(BuildConfiguration)/**/?(*.nupkg)'
Build output:
2018-11-27T23:04:24.6351310Z ##[section]Starting: PublishBuildArtifacts
2018-11-27T23:04:24.6353582Z ==============================================================================
2018-11-27T23:04:24.6353896Z Task : Publish Build Artifacts
2018-11-27T23:04:24.6353944Z Description : Publish build artifacts to Azure Pipelines/TFS or a file share
2018-11-27T23:04:24.6354007Z Version : 1.142.2
2018-11-27T23:04:24.6354046Z Author : Microsoft Corporation
2018-11-27T23:04:24.6354091Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=708390)
2018-11-27T23:04:24.6354156Z ==============================================================================
2018-11-27T23:04:26.1357631Z ##[section]Async Command Start: Upload Artifact
2018-11-27T23:04:26.1357755Z Uploading 1 files
2018-11-27T23:04:26.6373194Z File upload succeed.
2018-11-27T23:04:26.6373313Z Upload '/home/vsts/work/1/a' to file container: '#/1558454/drop'
2018-11-27T23:04:27.9231805Z Associated artifact 91 with build 806
2018-11-27T23:04:27.9231947Z ##[section]Async Command End: Upload Artifact
2018-11-27T23:04:27.9232436Z ##[section]Finishing: PublishBuildArtifacts
Note: The UI for azure-devops has changed and the artefacts (artifacts) are no longer created as a new tab but rather badly added into the report summary
The question:
How do I generate a specific version of nuget package IE: 1.0.%(Build.BuildId)?
My last attempt is
- task: DotNetCoreCLI#2
inputs:
command: pack
projects: '**/*ApiFramework.csproj'
# packageVersion:'1.0.$(Build.BuildId)'
where
packageVersion:'1.0.$(Build.BuildId)'
Will cause the build to fail
(the current branch is published here:https://github.com/cpoDesign/APIFramework/blob/cpoDesign-build-mods-1/azure-pipelines.yml)
after frustrating couple hours I have found the answer
Publish the generated nuget package into build artefacts
Generate a release to publish the nuget package
Build configuration
pool:
vmImage: 'Ubuntu 16.04'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: restore
projects: '**/*.csproj'
- script: dotnet test **/*.Tests.Unit.csproj --logger trx
- task: PublishTestResults#2
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
- script: dotnet pack /p:PackageVersion='1.0.$(Build.BuildId)' --configuration $(buildConfiguration) -o $(Build.ArtifactStagingDirectory)
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
contents: '**/$(BuildConfiguration)/**/?(*.nupkg)'
Release section
I have updated the release to trigger after each successful build
dotnet nuget push artefactName.APIFramework/drop/CPODesign.ApiFramework.1.0.$(Build.BuildId).nupkg -k $(myapiKey) -s https://api.nuget.org/v3/index.json
I can't see the contents as a valid input in the YAML for PublishBuildArtifacts#1
Do you mean to do a copy task first before you do the publish task. Like shown in the publish documentation?
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=vsts