如何最大程度地减少Bitbucket管道中的重复?
请参阅下面的示例脚本。某种程度上类似于我们的管道的样子,但并不是很明显。
steps:
- step: &test-sonar
name: test and analyze on SonarCloud
script:
- {some command}
- {some command}
- {some command}
- {some command}
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- pip install pytest
- pytest --cov=tests/ --cov-report xml:coverage-reports/coverage-report.xml --junitxml=test-reports/report.xml
- {some command}
- {some command}
- {some command}
- {some command}
- {some command}
- {some command}
- {some command}
- pipe: sonarsource/sonarcloud-scan:1.4.0
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.6
每当我们合并到主分支时,我们都会运行此脚本。
这将主要是也是相同的脚本集,但是pytest命令中的标志略有不同。
同样,对于预定的管道,脚本将大部分是相同的,并且有些细微地更改了pytest命令的标志。
我不想3次重复相同的脚本,我不确定如何使其更加重复使用。
我唯一能想到的是使用bitbucket变量来改变Pytest的执行方式,具体取决于管道的类型,但我仍将头缠绕在此方面。
see sample script below. somehow resembles how our pipeline looks like but not really obviously.
steps:
- step: &test-sonar
name: test and analyze on SonarCloud
script:
- {some command}
- {some command}
- {some command}
- {some command}
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- pip install pytest
- pytest --cov=tests/ --cov-report xml:coverage-reports/coverage-report.xml --junitxml=test-reports/report.xml
- {some command}
- {some command}
- {some command}
- {some command}
- {some command}
- {some command}
- {some command}
- pipe: sonarsource/sonarcloud-scan:1.4.0
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.6
this script is what we run whenever we merge into the master branch.
this would mostly also be the same set of scripts but the flags in the pytest command are slightly different.
and again for a scheduled pipeline, the scripts would be mostly the same with some slight changes the flags of the pytest command.
I wouldn't want to repeat the same script 3 times and I'm not sure how to make this a bit more reusable.
Only thing I can think of is using bitbucket variables to change how pytest is executed depending on the type of pipeline but I'm still wrapping my head around that as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的某些管道共享一个共同的初始化,我将我链接成
&&&code>运算符并将其存储在YAML锚点中的单个指令,就像
希望一样,
&&
操作员如果有任何故障(如果您的所有命令都会在失败上取消状态代码),则将算法短路(如果授予命令链,则命令链被Bitbucket算作单个指令,以便您将每个指令丢失度量以及控制台输出将被串联,因此有时很难确定每个命令输出何时启动或结束。理想情况下,您将yaml命令列表存储到锚点中,然后将它们与其他内联命令序列合并,但是上次我检查 https://github.com/yaml/yaml/yaml/issues/48 主要要点
现在我找不到JIRA问题,但是Atlassian也不愿在他们的结尾实施这一点。所以,我们在这里。
Some of my pipelines share a common initialization that I chain into a single instruction with the
&&
operator and store it in a yaml anchor likeHopefully, the
&&
operator will shortcircuit if anything failed (granted if all your commands will exit with a non-zero status code on failures), but the drawback is that the command chain is reckoned as a single instruction by Bitbucket so you will loose per-instruction time measures and also the console output will be concatenated so it is sometimes hard to tell when each command output starts or ends.Ideally, you would store yaml lists of commands into anchors and later merge them with other inline sequences of commands but this idea was having a bad reception last time I checked https://github.com/yaml/yaml/issues/48 the main points being
And now I can't find the jira issue but Atlassian was also reluctant to implement this on their end. So, here we are.