簡體   English   中英

Gitlab Ci 運行 gulp 后保存工件

[英]Gitlab Ci saving artifacts after running gulp

我正在嘗試運行 gulp 並將編譯后的文件保存到工件中,但我無法使其工作。

我的 gulp 文件在本地工作正常..

var gulp = require('gulp')
  , gutil = require('gulp-util')
  , concat = require('gulp-concat')
  , minifycss = require('gulp-minify-css')
  , uglify = require('gulp-uglify')
  , useref = require('gulp-useref');

var html = {
  source: 'src',
  target: 'dist'
}

var css = {
  source: 'app/scss',
  target: 'public/stylesheets'
};

var js = {
  source: 'src/js',
  target: 'dist/js'
};

gulp.task('html', function() {
  gulp.src([
    html.source + '/*.html'
  ])
  .pipe(useref({noAssets: true}))
  .pipe(gulp.dest(html.target));
});

gulp.task('css', function() {
  gulp.src([
    css.source + '/*.css'
  ])
  .pipe(minifycss())
  .pipe(concat('all.min.css'))
  .pipe(gulp.dest(css.target));
});

gulp.task('js', function() {
  gulp.src([
    js.source + '/*.js'
  ])
  .pipe(uglify({mangle:true}).on('error', gutil.log))
  .pipe(concat('all.min.js'))
  .pipe(gulp.dest(js.target));
});

gulp.task('default', ['html', 'css', 'js']);

gulp.task('watch', function() {
  gulp.watch(html.source + '/*.html', ['html']);
  gulp.watch(css.source + '/*.css', ['css']);
  gulp.watch(js.source + '/*.js', ['js']);
}); 

這是通過的my.yaml文件,但是文件my-build為空

stages:          # List of stages for jobs, and their order of execution
  - build
  - deploy
# This job runs in the build stage, which runs first.
build-job:
  stage: build
  image: node:10.24.1-alpine
  variables:
    TZ: "Europe/Stockholm"
  script:
    - echo "Compiling the code..."
    - mkdir my-build
    - cd my-build
    - npm i
    - npm i --g gulp
    - gulp css
    - echo "Compile complete."  
  artifacts:
    expire_in: 2 days
    paths: 
       - my-build
  allow_failure: false



deploy-job:      # This job runs in the deploy stage.
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."

這是我得到的錯誤:

$ echo "Compiling the code..."
Compiling the code...
$ mkdir my-build
$ cd my-build
$ npm i
added 392 packages from 215 contributors and audited 393 packages in 6.386s
7 packages are looking for funding
  run `npm fund` for details
found 14 vulnerabilities (2 low, 1 moderate, 8 high, 3 critical)
  run `npm audit fix` to fix them, or `npm audit` for details
$ npm i --g gulp
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
/usr/local/bin/gulp -> /usr/local/lib/node_modules/gulp/bin/gulp.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/gulp/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ gulp@4.0.2
added 323 packages from 220 contributors in 13.9s
$ gulp css
[19:19:04] Working directory changed to /builds/stefan_avramovic/nodejs-code-build
[19:19:04] Using gulpfile /builds/stefan_avramovic/nodejs-code-build/gulpfile.js
[19:19:04] Starting 'css'...
[19:19:04] Finished 'css' after 7.68 ms
$ tree $CI_PROJECT_DIR
/bin/sh: eval: line 128: tree: not found
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 127

gulp沒有將其 output 文件相對於您的工作目錄放置。 它將按照 gulpfile 中的配置放置 output 文件。 構建開始時,gulp 正在將工作目錄更改回項目根目錄:

[19:19:04] 工作目錄更改為 /builds/stefan_avramovic/nodejs-code-build
[19:19:04] 使用 gulpfile /builds/stefan_avramovic/nodejs-code-build/gulpfile.js

因此,根據您的target配置,您的輸出將放置在distpublic目錄中,相對於項目根目錄,而不是my-build - dest路徑的定義方式與 gulp 查找src文件的方式相同使用定義的相對路徑。

要解決此問題,您可以:

  1. 將您的工件目錄更改為您的dist / public目錄,因為 gulp 當前正在使用
  2. 更改您的 gulp 配置——使用不同的my-build目標或在 gulp dest選項中相應地設置cwd
  3. 構建完成后移動目標目錄(例如mv $CI_PROJECT_DIR/dist $CI_PROJECT_DIR/my-build

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM