Azure VSBuild上没有运行gulpfile.js

9o685dep  于 2022-12-08  发布在  Gulp
关注(0)|答案(2)|浏览(171)

我有一个.NET MVC项目,它在每次构建/// <binding AfterBuild='default' />后执行gulpfile.js。如果我在Visual Studio中本地构建项目,这会很好地工作。但我必须在每次提交后在Azure Pipeline上设置自动构建。VSBuild@1任务成功完成,但gulpfile.js未执行。
gulpfile.js

/// <binding AfterBuild='default' />
'use strict'
//include gulp
var gulp = require('gulp'),

//include plugins
templateCache = require('gulp-angular-templatecache'),
rimraf = require('rimraf'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
gutil = require('gulp-util'),
path = require('path');

//concatenate & minify JS Files
function scripts() {
    return gulp.src([...])
.pipe(concat('main.js'))
        .pipe(rename('main.min.js')) 
        .pipe(uglify()) 
        .on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
        .pipe(gulp.dest('Build/js'))//put main.js in this folder
}

exports.scripts = scripts;
exports.default = gulp.series(scripts);

Azure 管道

trigger:
- develop

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'
    
- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
zzwlnbp8

zzwlnbp81#

我最后做的是让Azure将工件部署到我的Web服务器。然后我有一个批处理文件来解压缩并将构建的文件移动到IIS目录。然后在批处理文件中,我有以下内容:

CD <<IIS directory>>
npm install
gulp --gulpfile "path\to\gulpfile.js"

通过这种方式,它在部署到IIS时执行gulfile.js以合并和最小化javascript文件。

vnzz0bqm

vnzz0bqm2#

根据您的注解,您可以在gulp构建之前添加一个任务,即执行npm安装:

steps:
- task: Npm@1
  displayName: 'npm install'
  inputs:
    command: install
    workingDir: '$(Build.SourcesDirectory)'
    verbose: false

请参阅thread:Azure DevOps gulp step fails with Local modules not found了解更多详细信息。

Update〉〉工件的目录是$(Build.ArtifactStagingDirectory),所以应该是D:\a\1\a,如果工件中没有js文件,可以使用Copy Files task将js文件复制到这个目录,然后再复制Publish Build Artifacts task

相关问题