gitlab定期备份_如何在一分钟内让GitLab为您做定期工作

gitlab定期备份

by Moe Ibrahim

通过易卜拉欣(Moe Ibrahim)

如何在一分钟内让GitLab为您做定期工作 (How to get GitLab to do periodic jobs for you in under a minute)

What would technology be without a computer doing periodic work?

没有计算机定期工作,技术将是什么?

Whether it’s your phone constantly checking your inbox for you, or getting timely alerts for weather or flight delays.

无论是您的手机不断为您检查收件箱,还是及时收到有关天气或航班延误的警报。

What about a bitcoin vs Canadian dollar price service, in just 56 seconds? No IFTTT, no Zapier, but no programming languages either — and no frameworks, no server or docker configuration, no Raspberry Pi, no AWS and no tests!

在短短56秒内,比特币兑加元价格服务怎么样? 没有IFTTT ,没有Zapier ,但是也没有编程语言-也没有框架,没有服务器或docker配置,没有Raspberry Pi,没有AWS和没有测试!

To make the example as universal as possible, we will only use 2 command lines:

为了使示例尽可能通用,我们将仅使用2个命令行:

  • one to GET the bitcoin price from an API

    一个从API获取比特币价格
  • and another to POST it to another service.

    另一个将其发布到另一个服务。

Of course you can make this more useful by posting the price to Twitter, Twilio, Telegram, Slack and so on. But here we will simply post it to putsreq.com so we can inspect the POST request.

当然,您可以通过将价格发布到Twitter,Twilio,Telegram,Slack等使价格更加有用。 但是在这里,我们将其简单地发布到putsreq.com,以便我们检查POST请求。

Then we will use GitLab-CI to schedule it to run everyday.

然后,我们将使用GitLab-CI安排它每天运行。

Level : All levels

级别 :所有级别

Requirements : Any web browser

要求 :任何Web浏览器

Let’s get you started :

让我们开始吧:

  1. Create a free account at gitlab.com (20 seconds)

    gitlab.com上 创建一个免费帐户 (20秒)

2. Create a new Project : Click on the New Project button to create a new repo, and in the name field type periodic-job or any other name. (9 seconds)

2. 创建一个新项目:单击“ 新建项目”按钮以创建一个新的仓库,然后在名称字段中键入periodic-job或任何其他名称。 (9秒)

Then save it by clicking on Create Project (1 second).

然后单击“ 创建项目”将其保存(1秒)。

3. Create a .gitlab-ci.yml file in this new project: Click on New File, copy and paste the following snippet into the .gitlab-ci.yml file, then click save (5 seconds)

3. 在这个新项目中创建一个.gitlab-ci.yml文件:单击“ 新建文件” ,将以下代码段复制并粘贴到.gitlab-ci.yml文件中,然后单击“保存”(5秒)

test:
script:
- btc=$(curl https://min-api.cryptocompare.com/data/price?fsym=BTC\&tsyms=CAD)
- curl -i -X POST https://putsreq.com/wkDdMQWhaOyalisaIe49 — data ‘price=CA$ ‘“${btc//[0-9\.]/}”

These are basically two simple commands. Here we can go further and add

这些基本上是两个简单的命令。 在这里,我们可以进一步添加

if [ $btc -ge 15000 -a $btc -lt 7000 ]; then

如果[$ btc -ge 15000 -a $ btc -lt 7000]; 然后

conditions, or even run a full bash script file, but let’s keep it simple.

条件,甚至运行完整的bash脚本文件,但让我们保持简单。

Click on the Commit changes button, and this will trigger it to build and run.

单击“ 提交更改”按钮,这将触发它进行构建和运行。

4. Schedule it to run everyday: click on the CI/CD icon to expand the menu, and select Schedules to set up a name and a timer for your periodic job to trigger. (11 seconds)

4. 计划它每天运行:单击CI / CD图标以展开菜单,然后选择“计划”以设置名称和计时器以触发您的定期作业。 (11秒)

5. Congrats! You’re done. Go to to this link in putsreq.com to see it in action. (10 seconds)

5.恭喜! 你完成了。 转到putsreq.com中的此链接以查看其运行情况。 (10秒)

This job will run everyday as long as your free 2000/month build minutes do not run out.

只要您每月免费的2000分钟构建时间没有用完,这项工作就会每天运行。

We haven’t even scratched the surface of what we can do with GitLab-CI — just think of all the possibilities of using it to create webhooks or connecting it to IFTTT and Zapier, which in turn would connect it to hundreds of services.

我们甚至还没有触及到使用GitLab-CI可以做的事情的表面-只是考虑使用它创建Webhooks或将其连接到IFTTT和Zapier的所有可能性,这反过来又会将其连接到数百种服务。

In the next article we will go through what we have just done, and how we can take it up a notch and create a webhook and use it to post to social media.

在下一篇文章中,我们将介绍我们刚刚完成的工作,以及如何将其记为缺口并创建一个Webhook并将其用于发布到社交媒体。

You can find the sample code here, and you can read the build logs here.

您可以在此处找到示例代码 ,也可以在此处阅读构建日志

翻译自: https://www.freecodecamp.org/news/56-seconds-to-get-gitlab-to-do-periodic-jobs-for-you-6a731b977559/

gitlab定期备份

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值