2
votes

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
1
Look at the file system. Are files being put in dist at the root of the working folder? If not, where are they being put? That's what you want to publish. – Daniel Mann
Yep, it's supposed then that your npm build should fill the dist directory. If that's not the case you might wanna point your publish task to the actual output OR use the copy task to copy files over to that folder – Andrey Stukalin

1 Answers

1
votes

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.