gocd

by Leonardo Lima

莱昂纳多·利马(Leonardo Lima)

如何将DangerJS集成到GoCD管道中 (How to integrate DangerJS into GoCD pipelines)

At my current company, we have recently migrated our CI infra from CircleCI to GoCD. After a few months using the new CI platform, I was comfortable enough to juice it up. One of the things that I was planning was integrating DangerJS — an amazing tool to expedite pull request reviews by performing configurable auto-checks on new code. What does it mean? No more time spent on writing PR comments like: “Oh, I believe you forgot X… Y… Z…”.

在我目前的公司中,我们最近将CI从CircleCI迁移到GoCD 。 在使用新的CI平台几个月后,我很舒服地将其榨干。 我正在计划的其中一项工作是集成DangerJS ,这是一个了不起的工具,可通过对新代码执行可配置的自动检查来加快请求请求的审查。 这是什么意思? 不再花时间写PR评论,例如:“哦,我相信您忘记了X…Y…Z…”。

My goal with this article is to help the next person pursuing this mission to improve their team’s Code Quality and PR review processes.

我在本文中的目标是帮助下一个执行此任务的人员改善其团队的代码质量和PR审查流程。

语境 (Context)

I have used Danger’s powers before (though integrated with Ruby) and I already knew that the initial setup would be quite straightforward…if only we were still using CircleCI!

我以前使用过Danger的功能(尽管已与Ruby集成在一起),并且我已经知道初始设置非常简单……只要我们仍在使用CircleCI!

On my first attempt to integrate, I tried googling “Integrating DangerJS with GoCD” with no luck. Also, after reading DangerJS’ documentation, I’ve found that there was no such thing as a native-straightforward integration with GoCD that I could use.

在第一次尝试进行集成时,我尝试了一下“将DangerJS与GoCD集成”,但没有成功。 另外,在阅读DangerJS的文档后,我发现没有可以与GoCD进行本机直接集成的东西。

That meant that I wouldn’t be able to easily integrate Danger’s checks into my CI flow. So I was left with a few options:

这意味着我将无法轻松将Danger的支票集成到我的CI流程中。 所以我有几个选择:

  1. Trying to make developers incorporate local manual runs of DangerJS commands;试图使开发人员并入DangerJS命令的本地手动运行;
  2. Build a specific pipeline in (CircleCI/CodeShip/FooBar) to run just DangerJS;在(CircleCI / CodeShip / FooBar)中构建特定的管道以仅运行DangerJS;
  3. Give up.放弃。

I didn’t like either of my options, and I was really frustrated after a few hours spent in Danger and GoCD settings. Then I stumbled upon the “Using danger and fake being on a CI” section in the DangerJS docs. That’s it! If I can fake being on a CI in my local machine, what’s the difference from faking a CI in a GoCD machine?

我不喜欢任何一种选择,在Danger和GoCD设置中花了几个小时后,我感到非常沮丧。 然后我偶然发现了DangerJS文档中的“在CI上使用危险和伪造 ”部分。 而已! 如果我可以在本地机器上伪造一个CI,那么与在GoCD机器上伪造一个CI有什么区别?

Afterwards, it was just a matter of figuring out how to emulate the same local behaviour inside GoCD’s infra.

之后,只需弄清楚如何在GoCD的基础设施内模拟相同的本地行为即可。

第一步 (First steps)

Before anything, you have to go through the official documentation in order to set up and start using DangerJS.

首先,您必须阅读官方文档才能设置和开始使用DangerJS。

Basically, what you need is to:

基本上,您需要执行以下操作:

  • Create your dangerfile.js file. There are a few examples here.

    创建您的angerousfile.js文件。 这里有一些例子 。

  • Create a bot account on GitHub/BitBucket for Danger to use

    在GitHub / BitBucket上创建一个机器人帐户以供危险使用

  • Open a PR with changed files to check your changes打开包含已更改文件的PR以检查您的更改
  • Run DangerJS locally against a PR link (the one you’ve just opened)针对PR链接(刚打开的那个)在本地运行DangerJS
  • Try to fake a CI environment in your local machine

    尝试在本地计算机上伪造CI环境

In the next section, I’ll go deeper in this last step since it is the critical part to make DangerJS work with GoCD.

在下一节中,我将进一步进行最后一步,因为这是使DangerJS与GoCD一起使用的关键部分。

在GoCD的环境中配置伪造的CI (Configuring a fake CI in GoCD’s environment)

First, if you still don’t have a detached GoCD pipeline to run only Pull Requests builds, I strongly recommend you to do so. Here is a guide if you need some help setting that up.

首先,如果您仍然没有分离的GoCD管道来仅运行Pull Requests构建,则强烈建议您这样做。 如果您需要一些帮助进行设置,请参考以下指南 。

Secondly, after creating your PR pipeline, create a new Job just for Danger:

其次,在创建您的PR管道之后,创建一个新的Job for Danger:

Now, to be able to fake a CI using Danger, you need to set a bunch of environment variables such as:

现在,为了能够使用Danger伪造CI,您需要设置一些环境变量,例如:

export DANGER_FAKE_CI="YEP"export DANGER_TEST_REPO="username/reponame"

In GoCD’s Pipeline Job settings, navigate to the Environment Variables tab and set those two env variables replacing the username/reponame placeholders with your own settings.

在GoCD的“管道作业”设置中,导航到“环境变量”选项卡,并设置这两个环境变量,以您自己的设置替换用户名/别名

After this first batch of configurations, in order to actually run Danger’s tests in GoCD, you can use a shell script that executes the same commands used to fake a CI in a local environment. Let’s call this file danger-build.sh.

在完成第一批配置后,为了在GoCD中实际运行Danger的测试,您可以使用Shell脚本,该脚本执行与在本地环境中伪造CI相同的命令。 我们将此文件称为危险文件build.sh。

# danger-build.sh
echo '— — START DANGER JS VERIFICATION —'
echo Testing against commits on PR: ${GO_SCM_PIPELINE_PR_URL}
DANGER_TEST_PR=${GO_SCM_PIPELINE_PR_ID} npx yarn danger ci
echo ‘ — — END OF DANGER JS VERIFICATION — — ‘

Please note that you’ll need node, npm/yarn previously installed in the GoCD available machine.

请注意,您将需要GoCD可用机器中先前安装的节点npm / yarn。

Did you notice those two GO_SCM variables? They are the catch that let you run your Danger verifications inside a GoCD machine.

您是否注意到了这两个GO_SCM变量 ? 它们是使您能够在GoCD机器上运行危险验证的功能。

Please pay special attention to the PR_ID variable since it’s the one that provides the PR reference to let Danger read, interpret the changes, and then write suggestions in the Pull Request.

请特别注意PR_ID变量,因为它是提供PR参考以使Danger读取,解释更改然后在Pull Request中写建议的变量。

In case you’re curious, those environment variables were generated by GoCD’s machines. They can be assessed by running the /usr/bin/printenv UNIX command in a build and inspecting the output.

如果您感到好奇,那么这些环境变量是由GoCD的机器生成的。 可以通过在构建中运行/usr/bin/printenv UNIX命令并检查输出来评估它们。

And that’s it!

就是这样!

After mapping the proper env variables in your Shell script, the DangerJS verifications will start running in GoCD’s pipelines next to your current test suite.

在Shell脚本中映射了正确的env变量后,DangerJS验证将开始在当前测试套件旁边的GoCD管道中运行。

To wrap up the steps:

总结步骤:

1. Setup the first DangerJS local files and settings

1.设置第一个DangerJS本地文件和设置

2. Create a specific Pipeline/Job in GoCD

2.在GoCD中创建特定的管道/作业

3. Discover and then map the proper environment variables inside a shell script to let GoCD run DangerJS

3.在Shell脚本中发现然后映射适当的环境变量,以使GoCD运行DangerJS

I hope that you’ve found the walkthrough helpful. If you have enjoyed the article please share with your fellow developers & managers and help spread the word.

我希望您发现本演练对您有所帮助。 如果您喜欢这篇文章,请与您的开发人员和经理分享,并帮助传播信息。

For any questions please feel free to ask in the comments section!

如有任何疑问,请随时在评论部分提问!

PS: Danger also has a lot of plugins options, check them out!

PS:Danger也有很多插件选项, 请检查 !

翻译自: https://www.freecodecamp.org/news/how-to-integrate-dangerjs-into-gocd-pipelines-7f930932ea07/

gocd

gocd_如何将DangerJS集成到GoCD管道中相关推荐

  1. LCE:一个结合了随机森林和XGBoost优势的新的集成方法

    随机森林 [Breiman, 2001] 和 XGBoost [Chen and Guestrin, 2016] 已成为解决分类和回归的许多挑战的最佳机器学习方法.Local Cascade Ense ...

  2. sudo apt install镜像_将Docker镜像安全扫描步骤添加到CI/CD管道

    使用GitlabCI和Trivy 介绍 如今,镜像安全扫描变得越来越流行.这个想法是分析一个Docker镜像并基于CVE数据库寻找漏洞.这样,我们可以在使用镜像之前知道其包含哪些漏洞,因此我们只能在生 ...

  3. 下一代Asp.net开发规范OWIN(3)—— Middleware

    Middleware是OWIN管道的基本组成单元,最后拼接的OWIN管道来处理客户端请求,输出网页.这篇文章,首先看看Web Form, MVC, Web API如何结合OWIN使用. 然后将如何编写 ...

  4. ASP.NET Web API 安全筛选器

    原文:https://msdn.microsoft.com/zh-cn/magazine/dn781361.aspx 身份验证和授权是应用程序安全的基础.身份验证通过验证提供的凭据来确定用户身份,而授 ...

  5. 面向.NET开发人员的Dapr——发布和订阅

    目录: 面向.NET开发人员的Dapr--前言 面向.NET开发人员的Dapr--分布式世界 面向.NET开发人员的Dapr--俯瞰Dapr 面向.NET开发人员的Dapr--入门 面向.NET开发人 ...

  6. 使用 InSpec 实现符合性即代码

    法规符合性是每个企业必须面对的一个现实问题.同时,随着改变业界格局的新技术以及客户对数字服务的期望的出现,竞争压力也随之增加.各行业能否在快速交付新产品和服务的同时,仍然履行法规符合性义务? 回答是肯 ...

  7. Soft NMS论文笔记

    论文:Improving Object Detection With One Line of Code. Navaneeth Bodla*, Bharat Singh*, Rama Chellappa ...

  8. Forrester《2021年应用安全现状报告》提要

     聚焦源代码安全,网罗国内外最新资讯! Forrester 公司的年度<应用安全现状报告>已成为检验组织机构AppSec 成熟度的试金石.软件开发行业和威胁局势不断演变,2021年的报告传 ...

  9. 服务器 解决方案_为什么无服务器解决方案不安全?

    服务器 解决方案 In recent years, the growth of Serverless has been monumental. More and more organisations ...

最新文章

  1. iOS开发JSON字符串和字典互转
  2. php 判断上传的是否是图片,php图片上传检测是否为真实图片格式
  3. opencl 实例源码
  4. java对象生命周期_Java对象生命周期和类生命周期
  5. Windows下如何安装和使用git
  6. 10大申请攻略+套磁技巧助你完胜美研申请
  7. 英语笔记-20151209
  8. 软件工程项目总结_复旦大学软件工程实验室来ASE实验室交流
  9. canvas反向裁剪技巧
  10. [导入]七大千年数学难题
  11. 如何把门禁卡做成你用不起的样子?B站up主自制迷你卡片,公司小区通刷,还带墨水屏的那种...
  12. android 播放语音anr,Android语音合成出现ANR
  13. 软件测试网上订餐系统,星月外卖网上订餐系统软件测试报告(正式).doc
  14. ActiveReports报表控件V11 SP1版本正式发布!
  15. Mac wifi 卡死
  16. elasticsearch7.1的一些自问自答
  17. 【转】Chrome浏览器截全屏
  18. python怎么画长方形_python怎么画矩形
  19. 高并发高流量网站架构详解
  20. Docker镜像原理及容器数据卷

热门文章

  1. 【OpenGL4.0】GLSL-使用Uniform Block实现着色器的数据共享
  2. 【C++基础学习】二维数组的动态分配及参数传递
  3. 存储与硬盘挂载 200305
  4. 前端开发 认识css 体验变色的效果 0228
  5. django-模型类关系-待整理
  6. 前端2018年12月9日 前端开发路上的小白心得--励志当个领路人
  7. Stream从Python切换到Go的原因
  8. 生产环境究竟是使用mysqldump还是xtrabackup来备份与恢复数据库?
  9. python之字符编码(二)
  10. iOS 禁止手势滑动翻页