【问题标题】:How to use the image between steps in bitbucket-pipelines如何在 bitbucket-pipelines 中的步骤之间使用图像
【发布时间】:2022-03-03 21:15:09
【问题描述】:

如果有人可以帮助我为我的 php 环境设置 bitbucket-pipeline,我将不胜感激。我想要成功的是:

  1. 第一步构建镜像
  2. 在第二步中,运行一些 QA 工作,例如单元测试、代码嗅探器等。
  3. 部署到预生产环境

目前,我坚持从第一步开始重复使用图像。这就是我的 bitbucket-pipelines.yml 的样子:

pipelines:
  branches:
    develop:
      - step:
          name: Build docker image
          caches:
            - composer
          script:
            - apt-get update && apt-get install -y unzip
            - docker-php-ext-install mysqli pdo_mysql json sockets
            - curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
            - composer install
      - parallel:
          - step:
              caches:
                - composer
              name: Unit tests
              script:
                - vendor/bin/phpunit
          - step:
              caches:
                - composer
              name: Code sniffer
              script:
                - composer phpcs:all
      - step:
          name: Deploy to preprod
          script:
            - echo "Deployment"

我在这里得到的是: bash: vendor/bin/phpunit: No such file or directory - 来自“单元测试”步骤 和bash: composer: command not found - 来自“代码嗅探器”步骤

我已经尝试将 docker/composer 设置为缓存,在第一步中保存图像并在第二步中将其导入,但仍然无法正常工作。

【问题讨论】:

    标签: php docker bitbucket-pipelines


    【解决方案1】:

    在不同步骤之间共享内容的一种方法是使用Artifacts

    基本上,bitbucket 在单独的 docker 容器中启动每个步骤。因此,在步骤之间重用材料的一种方法是创建一个工件。 该链接应该为您提供足够的信息。

    例如:

    - step: &build
        caches:
          - node
        name: Build
        script:
          - npm install
          - npm run build
        artifacts: # defining the artifacts to be passed to each future step.
          - dist/**
    
    - step: &read-from-artifact
        name: Read from the artifact saved in the previous step
        script:
          - echo "Read artifact (dist folder) saved in previous step"
          - ls -la dist/
    

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 2018-01-15
      • 2018-09-02
      • 2017-07-07
      • 2023-01-21
      • 2019-07-05
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      相关资源
      最近更新 更多