Gitlab Ci 在 运行 gulp 之后保存工件

Gitlab Ci saving artifacts after running gulp

我正在尝试 运行 gulp 并将编译后的文件保存到工件中,但我无法让它工作。

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

const process = require('process');
var css = {
  src: process.cwd() + '/app/scss/style.scss',
  dest: process.cwd() +'/public/stylesheets'
};
var gulp = require('gulp');
var sass = require('gulp-sass')(require('sass'));

function buildStyles() {
  return gulp.src(css.src)
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest(css.dest));
};

exports.buildStyles = buildStyles;

这是我通过的.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:12.22.6-alpine
  variables:
    TZ: "Europe/Stockholm"
  script:
    - echo "Compiling the code..."
    - mkdir my-build
    - cd my-build
    - npm i
    - npm i --g gulp
    - gulp buildStyles
    - 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."

gulp 没有将其输出文件放置在相对于您的工作目录的位置。它将按照您的 gulp 文件中的配置放置输出文件。当构建开始时,gulp 是 changing the working directory 回到项目根目录:

[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

因此,根据您的 target 配置,您的输出将放置在相对于项目根目录的 distpublic 目录中,而不是 my-build -- dest 路径的定义方式与 gulp 使用定义的相对路径查找 src 文件的方式相同。

要解决此问题,您可以:

  1. 将工件目录更改为 dist/public 目录,因为 gulp 当前正在使用
  2. 更改您的 gulp 配置——使用不同的目标 my-build 或在您的 gulp dest options[=35= 中相应地设置 cwd ]
  3. 构建完成后移动目标目录(例如mv $CI_PROJECT_DIR/dist $CI_PROJECT_DIR/my-build