【问题标题】:Appveyor - .NET MVC and NodeJS buildAppveyor - .NET MVC 和 NodeJS 构建
【发布时间】:2018-05-30 16:47:04
【问题描述】:

我有一个 .NET MVC 应用程序,它承载了一个 Angular 应用程序。

我需要使用 Appveyor 配置我的构建 yaml 以构建 .NET 解决方案,还需要 cd 进入 Angular 文件夹并执行 npm install 和 npm build。

我的 Appveyor 文件看起来像

# Project configuration
version: $(versionNumber)-{branch}.{build}
# Location of the cloned repo on the build server
clone_folder: c:\projects\something

# Environment Variables
environment: 
  nodejs_version: "8"
  versionNumber: "1.9.0"
  devpackageVersion: "$(versionNumber)-alpha.$(APPVEYOR_BUILD_NUMBER)"
  relpackageVersion: "$(versionNumber).$(APPVEYOR_BUILD_NUMBER)"
  buildFolder: "$(APPVEYOR_BUILD_FOLDER)"

  # Install scripts. (runs after repo cloning)
install:
  # Get the latest stable version of Node.js
  - ps: Install-Product node $env:nodejs_version

# branches to build
branches:
  only:
    - develop
    - /releases.*/
    - /features.*/
    - /bugfixes.*/
    - /hotfixes.*/

# Nuget Restore
nuget:
 # Retrieve packages from account feed
 account_feed: true
 # Retrieve packages from project feed
 project_feed: true

image: Visual Studio 2017

# Build configuration
platform: Any CPU
configuration: Release

# Step to execute before build
before_build:
  # Restore NPM packages
 - ps: cd angular
 - ps: npm install
 - ps: cd ..
  # Restore Nuget packages
 - cmd: nuget restore something.sln -Verbosity quiet

# Step to build the solution
build:
 parallel: true
 # Visual Studio solution to build
 project: something.sln
 verbosity: minimal

# Conditional configuration depending on branch
for:
-
  branches:
    only:
      - develop
      - /features.*/
      - /bugfixes.*/

  # Powershell to pack files for Octopus
  after_build:    
    - ps: octo pack --id=something.something --version="$env:devpackageVersion" --basePath="$env:buildFolder"\something\ --outFolder="$env:buildFolder"\packages\

  # Step to create the artifact in AppVeyor
  artifacts:
    # Path to the packages created above
    - path: 'packages\*.nupkg'

  # Step to orchestrate Octopus Deploy
  deploy:
    - provider: Octopus
      push_packages: true
      create_release: true
      project: something
      create_release_advanced: --releaseNumber=$(devpackageVersion)
      deploy_release: true
      environment: QA
      server: https://something
      api_key: something
      deploy_wait: false
      push_packages_advanced: --ignoreSslErrors

# Conditional configuration depending on branch
-
  branches:
    only:
      - /releases.*/
      - /hotfixes.*/

  # Powershell to pack files for Octopus
  after_build:
    - ps: octo pack --id=something.something --version="$env:relpackageVersion" --basePath="$env:buildFolder"\something\ --outFolder="$env:buildFolder"\packages\

  # Step to create the artifact in AppVeyor
  artifacts:
    # Path to the packages created above
    - path: 'packages\*.nupkg'

  # Step to orchestrate Octopus Deploy
  deploy:
    - provider: Octopus
      push_packages: true
      create_release: true
      project: something
      create_release_advanced: --releaseNumber=$(relpackageVersion)
      deploy_release: true
      environment: QA
      server: https://something
      api_key: something
      deploy_wait: false
      push_packages_advanced: --ignoreSslErrors

但这似乎进入了 npm install 阶段,然后返回 404 或

+ npm install
+ ~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (npm WARN tar EN...2\package.json':String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

我终其一生都无法弄清楚发生了什么。

如何执行 npm install 和 npm build,同时构建我的 .NET 解决方案

【问题讨论】:

    标签: .net node.js appveyor


    【解决方案1】:

    如果您的package.json 文件不是位于存储库的根目录,请尝试将您的- ps: npm install 脚本更改为- ps: npm install ./src/folder1(其中src/folder1 是包含您的package.json 文件的文件夹相对于你的 repo 的根目录)。

    如果您的 package.json 在您的存储库的根目录,然后尝试将您的 - ps: npm install 脚本从 before_build: 部分移动到 install: 部分,以便您的 yml 看起来像这样:

    install:
      - ps: Install-Product node $env:nodejs_version
      - npm install                  #or - npm install ./src/folder1
    

    我遇到了和你一样的问题(一个 appveyor 构建,用于托管一个需要安装节点包的 Angular 应用程序的 .NET 解决方案),以上对我有用。

    有关 NodeJS 的 appveyor 文档,请参阅 here

    【讨论】:

      【解决方案2】:

      - ps: npm install 替换为- cmd: npm install 或简单的- npm installnpm 将输出写入stdErr,这使得 AppVeyor 上的自定义 PowerShell 主机不满意。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-13
        相关资源
        最近更新 更多