简体   繁体   English

如何在 bitbucket-pipelines.yml 文件的同一步骤中构建和部署 jar?

[英]How to build and deploy jar in same step in bitbucket-pipelines.yml file?

I have a bitbucket-pipelines.yml file actually steps are working good.我有一个 bitbucket-pipelines.yml 文件,实际上步骤运行良好。 But what I want to do is deploy the backend jar after build is finished.但我想做的是在构建完成后部署后端 jar。 But as you see build image and ubuntu image are in different steps and I cannot integrate them together.但是正如您所见,构建映像和 ubuntu 映像处于不同的步骤中,我无法将它们集成在一起。

# This is an example Starter pipeline configuration
pipelines:
  default:
    
    - step:
        name: 'Frontend Build'
        image: node:16.4.2
        script:
          - cd frontend
          - npm install
    - step:
        name: 'Backend Build and Package'
        image: maven:3.8.3-openjdk-17
        script:
          - cd backend
          - mvn clean package
    - step:
        name:  'Deploy'
        image: ubuntu:16.04
        script:
          - apt-get update
          - apt-get install curl -y
          - apt-get install sshpass -y
          - sshpass -f "sshkey.pub" scp backend/target/backend-0.0.1-SNAPSHOT.jar root@164.65.55.278:/root/artifacts2

If I put build and deploy steps togetger as follows:如果我将构建和部署步骤放在getger中,如下所示:

- step:
        name:  'Deploy'
        image: ubuntu:16.04
        script:
          - apt-get update
          - apt install maven
          - apt install -y openjdk-17-jdk
          - cd backend
          - mvn clean package
          - apt-get install curl -y
          - apt-get install sshpass -y
          - sshpass -f "sshkey.pub" scp backend/target/backend-0.0.1-SNAPSHOT.jar root@167.71.54.246:/root/artifacts2

Then I get storage error:然后我得到存储错误:

          Need to get 65.5 MB of archives.
After this operation, 175 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.

If I don't put deploy in same step with build then it cannot find the jar file... How can I achieve this in different steps?如果我没有将部署与构建放在同一步骤中,那么它找不到 jar 文件......我怎样才能在不同的步骤中实现这一点?

  1. The message you refer to as 'storage error' looks like a prompt from apt install maven - it is missing the -y option which stands for automatic 'yes' to all prompts (and you're using it correctly in the steps below).您称为“存储错误”的消息看起来像是来自apt install maven的提示 - 它缺少代表所有提示的自动“是”的-y选项(并且您在以下步骤中正确使用它)。

  2. Downloading missing packages dynamically in the pipeline step with a package manager is an acceptable solution, though it slows down the step execution.使用 package 管理器在管道步骤中动态下载丢失的包是一种可接受的解决方案,尽管它会减慢步骤的执行速度。 To speed things up, you can create your custom build environment image and host it either publicly or privately.为了加快速度,您可以创建自定义构建环境映像并公开或私下托管它。 You can tailor this image for your needs, so that it contains all the dependencies needed for the step pre-installed.您可以根据需要定制此映像,以便它包含预安装步骤所需的所有依赖项。 Check out this page for details.查看此页面了解详情。

  3. Finally, if possible, I would advise to not combine the build and deploy steps into a single one.最后,如果可能的话,我建议不要将构建和部署步骤合并为一个。 Build step should produce an immutable artefact, which is then deployed to multiple environments - and you'll have a guarantee that it's the exact same artefact.构建步骤应该产生一个不可变的人工制品,然后将其部署到多个环境中——并且您将保证它是完全相同的人工制品。 Also, it is quite handy for rollbacks - re-deploys will be much faster (no time wasted on building the artefact), and again you'll be confident that you're rolling back to the exact version of the artefact required.此外,它对于回滚非常方便 - 重新部署将更快(不会浪费时间构建工件),并且您将再次确信您正在回滚到所需的工件的确切版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM