Bitbucket的拉取请求能显示由管道生成的文件的更改吗?

huangapple go评论58阅读模式
英文:

Can a Bitbucket pull request show the changes to a file generated by a pipeline

问题

I am working on a Node.js-based project. I have an npm script that generates a text file report of the code (e.g. npm run scriptThatGeneratesReport generates a file report.txt, replacing the contents of any existing file with the same name).

Currently, when we are ready to create a pull request on a given branch, we run this script and commit the change to report.txt. Then when we create the pull request, the reviewers can see the change to this file along with the other code changes included in the branch as compared to the destination branch. However, we don't need this report file in the repository. We only commit it so we can see what changed while reviewing the pull request.

Is there a way to automate this step so we don't have to manually run scriptThatGeneratesReport and commit report.txt to the branch?

I can add the script to our Bitbucket pipeline so it gets run and the file generated with something like this:

image: node:18

definitions:
  steps:
    - step: &run-script
        name: Run script that generates output
        caches:
          - node
        script:
          - npm install
          - npm run scriptThatGeneratesReport

pipelines:
  pull-requests:
    "**":
      - step: *run-script
  branches:
    master:
      - step: *run-script

But I would need to also run it for the destination branch and somehow have Bitbucket show the changes as part of the pull request diff. Is there a way to do this?

英文:

I am working on a Node.js-based project. I have an npm script that generates a text file report of the code (e.g. npm run scriptThatGeneratesReport generates a file report.txt, replacing the contents of any existing file with the same name).

Currently, when we are ready to create a pull request on a given branch, we run this script and commit the change to report.txt. Then when we create the pull request, the reviewers can see the change to this file along with the other code changes included in the branch as compared to the destination branch. However, we don't need this report file in the repository. We only commit it so we can see what changed while reviewing the pull request.

Is there a way to automate this step so we don't have to manually run scriptThatGeneratesReport and commit report.txt to the branch?

I can add the script to our Bitbucket pipeline so it gets run and the file generated with something like this:

image: node:18

definitions:
  steps:
    - step: &run-script
        name: Run script that generates output
        caches:
          - node
        script:
          - npm install
          - npm run scriptThatGeneratesReport

pipelines:
  pull-requests:
    "**":
      - step: *run-script
  branches:
    master:
      - step: *run-script

But I would need to also run it for the destination branch and somehow have Bitbucket show the changes as part of the pull request diff. Is there a way to do this?

答案1

得分: 1

默认情况下,Bitbucket会在流水线结束时丢弃对拉取代码所做的任何更改,包括您生成的报告。要避免这种情况,您需要将更改推送回您的分支。Bitbucket有一篇详细文章介绍了如何做到这一点:

- git add report.txt
- git commit -m "提交消息"
- git push

至于在目标分支上运行您的命令,您将不得不将其拉取到一个单独的文件夹中。甚至最好让您的Bitbucket流水线将工作交给一个sh脚本,该脚本将具有比Bitbucket提供的YAML更多的脚本功能。

英文:

By default, Bitbucket will discard any changes it did to the pulled code at the end of the pipeline, including the report you generate. To avoid this, you need to push changes back into your branch. Bitbucket has a detailed article on how you can do this:

- git add report.txt
- git commit -m "Commit message"
- git push

As for running your command on the destination branch, you will have to pull it to a separate folder. It might even be better to have your Bitbucket pipeline hand off the job to a sh script that would have far more scripting functionality than the yaml provided in Bitbucket.

huangapple
  • 本文由 发表于 2023年6月1日 07:10:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76377799.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定