0
votes

I'm setting up a release pipeline for my ASP.NET Core Angular Application from Visual Studio 2017 and I'm running into major problems with the npm task locating the package.json file. I know the file is there - it was initially in the ClientApp folder, and I've also added it to the main folder, and the dist folder for testing purposes while I was trying to figure out why it doesn't like my file!

I have literally tried every possibility, including using the $(System.DefaultWorkingDirectory). This is my first time working in Azure DevOps and my first time trying to set up pipelines. I've googled endlessly and even tried re-queueing the build pipeline.

It's completely possible I've set up the wrong type of release pipeline. I chose an empty job and I have 3 tasks - npm install, npm build, and publish artifact (I've been trying to follow some online tutorials). I also made my build pipeline from an ASP.Net Core template, ran the yaml file, etc.

As a note, I did install node.js and angular, and ensured the proper files are in my dist folder. I've added a web.config file, added it to my assets in the angular json file. I have also added a small script to the package.json folder to actually build.

  "project": {
    "name": "Test"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "src/web.config"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "styles.css",
        "../node_modules/bootstrap/dist/css/bootstrap.min.css"
      ],
      "scripts": [],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
 "name": "Test",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "prod-build-dev": "ng build --prod --build-optimizer",
    "prod-build-staging": "ng build --prod --configuration=staging --build-optimizer"
  },

I expect the npm task to find the package.json file but that's not what is happening. Please see these error messages, each of which shows up for a different input for the working folder that contains package.json. In one, it cannot find the directory. In the other, it cannot find the file.

Error #1: Error: Npm failed with return code: 4294963238

paired with:

14 error enoent ENOENT: no such file or directory, open 'D:\a\r1\a\package.json' 2019-08-10T15:08:12.2500818Z 15 error enoent This is related to npm not being able to find a file.

and

Error #2: Error: ENOENT: no such file or directory, stat 'D:\a\r1\a\Test\ClientApp\dist'

4
Try $(Build.SourcesDirectory) for CI side.jessehouwing
When entering the release side of things, artefacts are downloaded to the artefacts folder. They take on a naming structure of $(System.ArtifactsDirectory)/{Artifact Alias for the whole build}/{Artefact name in the publish pipeline artifact task}/. Often it helps to run a dir /s /b or find . from the $(System.WorkFolder) to see where stuff ended up.jessehouwing
What does your repo directory structure look like? That's a fairly important thing to know before anyone can suggest settings and commands for you to try.Krenom
@Krenom Repo Test>Test>>ClientApp>>>package.jsonAshleigh
I have just noticed that the log says: Agent.BuildDirectory=undefined. Perhaps I need to find a way to define this, because it then tries to create a temporary directory, removes it, and then it fails.Ashleigh

4 Answers

2
votes

Building Release Pipeline in Azure DevOps with Angular Application - cannot find working folder that contains package.json

According to the error message:

no such file or directory, open 'D:\a\r1\a\package.json'

It seems you are not using the correct path for the option Working folder that contains package.json. You are searching the package.json file in the root folder of artifact directory. D:\a\r1\a\.

To resolve this issue, you should specify the working folder like $(System.DefaultWorkingDirectory)\Test\Test\ClientApp

Note: You should publish the project/solution when you build the pipeline, otherwise, we could not get the file in the release pipeline.

Hope this helps.

0
votes

Welcome to the painful world of Azure devops builds. They're not too bad once you've gotten used to them over the course of a year or so, but they're still a pain in the backside with little in the way of useful documentation (or helpful SO posts).

In theory, you want your build steps to look something like this at its most basic:

  • npm install
  • ng build
  • Copy/publish artifacts

1. npm install

npm task - v1.*

Command: install

Working folder that contains package.json: Use the ... to navigate to Test>Test>ClientApp (given your latest comment about your repo structure).

2. ng build

Note: we use a PS script to do a little extra, but it boils down to running, essentially, ng build.

PowerShell - v2.*

Type: Inline

Script: ng build --output-path=$(Build.ArtifactStagingDirectory)

Advanced > Working Directory: Use the ... to navigate to your Test>Test>ClientApp directory.

3. Copy/publish artifacts

Publish build artifacts - v1.*

Path to publish: $(Build.ArtifactStagingDirectory)

Pick your name and location...

In theory - a very big theory - that should work. No matter how deep you bury your Angular app, so long as it has the standard Angular cli directory structure, it should all be possible to build from that top-level directory.

> Test
  > Test
    > ClientApp -- top level dir
      > src
      > e2e
      angular.json
      package.json
      etc...
0
votes

I had the same issue and it was because the linux server that the pipeline runs on is case sensitive to directory names whereas windows where I was testing the script wasn't.

0
votes

In certain scenarios you may need to tell AzureDevOps explicitly to actually check out the repo in question, by adding a step in your job definition.

jobs:
  - checkout: self