jenkins 如何在多阶段构建中提取覆盖率报告?

yptwkmov  于 2022-11-02  发布在  Jenkins
关注(0)|答案(1)|浏览(162)

我想在多级构建中构建Docker映像时提取覆盖率报告。之前我使用Jenkins Docker插件通过image.inside执行测试,但现在我使用以下命令执行测试,但无法提取覆盖率报告。

docker build -t myapp:test --cache-from registry/myapp:test --target test --build-arg BUILDKIT_INLINE_CACHE=1 .

有没有什么方法可以像下面的函数一样挂载Jenkins工作区而不运行docker映像?有一个--output标志,但我不明白如果它能工作,我该如何使用它。或者可以通过RUN --mount=type ...

image.inside('-u root -v $WORKSPACE/coverage:/var/app/coverage') {
      stage("Running Tests") {
        timeout(10) {
          withEnv(["NODE_ENV=production"]) {
            sh(script: "cd /var/app; yarn run test:ci")
        }

停靠文件

FROM node:16.15.0-alpine3.15 as base
WORKDIR /var/app
RUN --mount=type=cache,target=/var/cache/apk \
    apk add --update --virtual build-dependencies build-base \
    curl \
    python3 \
    make \
    g++ \
    bash 
COPY package*.json ./
COPY yarn.lock ./
COPY .solidarity ./
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn && \
    yarn install --no-progress --frozen-lockfile --check-files && \
    yarn cache clean
COPY . .

FROM base as test
ENV NODE_ENV=production
RUN ["yarn", "run", "format:ci"]
RUN ["yarn", "run", "lint:ci"]
RUN ["yarn", "run", "test:ci"]

FROM base as builder
RUN yarn build

FROM node:16.15.0-alpine3.15 as production
WORKDIR /var/app
COPY  --from=builder /var/app /var/app
CMD ["yarn", "start:envconsul"]
sq1bmfud

sq1bmfud1#

您可以使用要撷取的输出建立后台文件:

FROM node:16.15.0-alpine3.15 as base
WORKDIR /var/app
RUN --mount=type=cache,target=/var/cache/apk \
    apk add --update --virtual build-dependencies build-base \
    curl \
    python3 \
    make \
    g++ \
    bash 
COPY package*.json ./
COPY yarn.lock ./
COPY .solidarity ./
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn && \
    yarn install --no-progress --frozen-lockfile --check-files && \
    yarn cache clean
COPY . .

FROM base as test
ENV NODE_ENV=production
RUN ["yarn", "run", "format:ci"]
RUN ["yarn", "run", "lint:ci"]
RUN ["yarn", "run", "test:ci"]

FROM scratch as test-out
COPY --from=test /var/app/coverage/ /

FROM base as builder
RUN yarn build

FROM node:16.15.0-alpine3.15 as production
WORKDIR /var/app
COPY  --from=builder /var/app /var/app
CMD ["yarn", "start:envconsul"]

然后,您可以使用以下内容进行构建:

docker build \
  --output "type=local,dest=${WORKSPACE}/coverage" \
  --target test-out .

相关问题