{"id":3233,"date":"2018-03-06T00:00:00","date_gmt":"2018-03-06T07:00:00","guid":{"rendered":"http:\/\/yyc.ninja\/index.php\/2018\/03\/06\/how-to-get-gitlab-to-do-periodic-jobs-for-you-in-under-a-minute-6a731b977559\/"},"modified":"2022-02-24T12:15:55","modified_gmt":"2022-02-24T19:15:55","slug":"how-to-get-gitlab-to-do-periodic-jobs-for-you-in-under-a-minute-6a731b977559","status":"publish","type":"post","link":"https:\/\/yyc.ninja\/index.php\/2018\/03\/06\/how-to-get-gitlab-to-do-periodic-jobs-for-you-in-under-a-minute-6a731b977559\/","title":{"rendered":"How to get GitLab to do periodic jobs for you in under a\u00a0minute"},"content":{"rendered":"<h3 id=\"a022\" class=\"graf graf--h3 graf--leading graf--title\">How to get GitLab to do periodic jobs for you in under a\u00a0minute<\/h3>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<p><strong>[Unedited]<\/strong><\/p>\n<p id=\"cf62\" class=\"graf graf--p graf-after--figure\">What would technology be without a computer doing periodic work?<\/p>\n<p id=\"5434\" class=\"graf graf--p graf-after--p\">Whether it\u2019s your phone constantly checking your inbox for you, or getting timely alerts for weather or flight delays.<\/p>\n<p id=\"7e77\" class=\"graf graf--p graf-after--p\">What about a bitcoin vs Canadian dollar price service, in just 56 seconds? No <em class=\"markup--em markup--p-em\">IFTTT<\/em>, no <em class=\"markup--em markup--p-em\">Zapier<\/em>, but no programming languages either\u200a\u2014\u200aand no frameworks, no server or docker configuration, no Raspberry Pi, no AWS and no tests!<\/p>\n<p id=\"8c90\" class=\"graf graf--p graf-after--p\">To make the example as universal as possible, we will only use 2 command lines:<\/p>\n<ul class=\"postList\">\n<li id=\"14cb\" class=\"graf graf--li graf-after--p\">one to GET the bitcoin price from an API<\/li>\n<li id=\"0440\" class=\"graf graf--li graf-after--li\">and another to POST it to another service.<\/li>\n<\/ul>\n<p id=\"1e25\" class=\"graf graf--p graf-after--li\">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.<\/p>\n<p id=\"fbaf\" class=\"graf graf--p graf-after--p\">Then we will use GitLab-CI to schedule it to run everyday.<\/p>\n<blockquote id=\"7891\" class=\"graf graf--blockquote graf-after--p\"><p><strong class=\"markup--strong markup--blockquote-strong\">Level<\/strong>\u00a0: All levels<\/p><\/blockquote>\n<blockquote id=\"4075\" class=\"graf graf--blockquote graf-after--blockquote\"><p><strong class=\"markup--strong markup--blockquote-strong\">Requirements<\/strong>\u00a0: Any web browser<\/p><\/blockquote>\n<p id=\"c4f5\" class=\"graf graf--p graf-after--blockquote\">Let\u2019s get you started\u00a0:<\/p>\n<ol class=\"postList\">\n<li id=\"3d10\" class=\"graf graf--li graf-after--p\"><strong class=\"markup--strong markup--li-strong\">Create a free account<\/strong> at <a class=\"markup--anchor markup--li-anchor\" href=\"https:\/\/gitlab.com\/users\/sign_in\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/gitlab.com\/users\/sign_in\">gitlab.com<\/a> (20 seconds)<\/li>\n<\/ol>\n<p id=\"a990\" class=\"graf graf--p graf-after--li\">2. <strong class=\"markup--strong markup--p-strong\">Create a new Project\u00a0:<\/strong> Click on the <strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">New Project<\/em><\/strong> button to create a new repo, and in the name field type <em class=\"markup--em markup--p-em\">periodic-job<\/em> or any other name. (9 seconds)<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<p id=\"fda9\" class=\"graf graf--p graf-after--figure\">Then save it by clicking on <strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">Create Project<\/em><\/strong> (1 second).<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<p id=\"9a96\" class=\"graf graf--p graf-after--figure\">3. <strong class=\"markup--strong markup--p-strong\">Create a\u00a0.gitlab-ci.yml file in this new project: <\/strong>Click on <strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">New File<\/em><\/strong>, copy and paste the following snippet into the\u00a0.gitlab-ci.yml file, then click save (5 seconds)<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<pre id=\"e7a1\" class=\"graf graf--pre graf-after--figure\">test:<\/pre>\n<pre id=\"aa54\" class=\"graf graf--pre graf-after--pre\"> script:<\/pre>\n<pre id=\"5c99\" class=\"graf graf--pre graf-after--pre\"> - btc=$(curl <a class=\"markup--anchor markup--pre-anchor\" href=\"https:\/\/min-api.cryptocompare.com\/data\/price?fsym=BTC%5C&amp;tsyms=CAD%29\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/min-api.cryptocompare.com\/data\/price?fsym=BTC\\&amp;tsyms=CAD)\">https:\/\/min-api.cryptocompare.com\/data\/price?fsym=BTC\\&amp;tsyms=CAD)<\/a><\/pre>\n<pre id=\"9ea0\" class=\"graf graf--pre graf-after--pre\">- curl -i -X POST <a class=\"markup--anchor markup--pre-anchor\" href=\"https:\/\/putsreq.com\/wkDdMQWhaOyalisaIe49\/inspect\" target=\"_blank\" rel=\"nofollow noopener\" data-href=\"https:\/\/putsreq.com\/wkDdMQWhaOyalisaIe49\/inspect\">https:\/\/putsreq.com\/wkDdMQWhaOyalisaIe49<\/a> \u2014 data \u2018price=CA$ \u2018\u201c${btc\/\/[0-9\\.]\/}\u201d<\/pre>\n<p id=\"3ade\" class=\"graf graf--p graf-after--pre\">These are basically two simple commands. Here we can go further and add<\/p>\n<p id=\"e302\" class=\"graf graf--p graf-after--p\"><a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/hackernoon.com\/71-seconds-to-build-your-free-custom-webhook-illustrated-step-by-step-7a09b9e240ba\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/hackernoon.com\/71-seconds-to-build-your-free-custom-webhook-illustrated-step-by-step-7a09b9e240ba\"><em class=\"markup--em markup--p-em\">if [ $btc -ge 15000 -a $btc -lt 7000 ]; then<\/em><\/a><\/p>\n<p id=\"bc55\" class=\"graf graf--p graf-after--p\">conditions, or even run a full bash script file, but let\u2019s keep it simple.<\/p>\n<p id=\"b6ad\" class=\"graf graf--p graf-after--p\">Click on the <strong class=\"markup--strong markup--p-strong\"><em class=\"markup--em markup--p-em\">Commit changes<\/em><\/strong> button, and this will trigger it to build and run.<\/p>\n<p id=\"da92\" class=\"graf graf--p graf-after--p\">4. <strong class=\"markup--strong markup--p-strong\">Schedule it to run everyday:<\/strong> 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)<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<p id=\"24ef\" class=\"graf graf--p graf-after--figure\">5. Congrats! You\u2019re done. Go to to <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/putsreq.com\/wkDdMQWhaOyalisaIe49\/inspect\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/putsreq.com\/wkDdMQWhaOyalisaIe49\/inspect\">this link in putsreq.com<\/a> to see it in action. (10 seconds)<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*HHVkCUSmaGkFPTx06jjZKw.png\" alt=\"\" \/><figcaption>click on New schedule\u00a0button<\/figcaption><\/figure>\n<p id=\"ba98\" class=\"graf graf--p graf-after--figure\">This job will run everyday as long as your free 2000\/month build minutes do not run out.<\/p>\n<p id=\"f971\" class=\"graf graf--p graf-after--p\">We haven\u2019t even scratched the surface of what we can do with GitLab-CI\u200a\u2014\u200ajust think of all the possibilities of using it to create webhooks or <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/medium.com\/@YYC_Ninja\/99-seconds-to-make-bitcoin-call-your-phone-number-a8cbd9740f76\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/medium.com\/@YYC_Ninja\/99-seconds-to-make-bitcoin-call-your-phone-number-a8cbd9740f76\">connecting it to IFTTT<\/a> and Zapier, which in turn would connect it to hundreds of services.<\/p>\n<p id=\"c1f4\" class=\"graf graf--p graf-after--p\">In <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/medium.com\/@YYC_Ninja\/71-seconds-to-build-your-free-custom-webhook-illustrated-step-by-step-7a09b9e240ba\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/medium.com\/@YYC_Ninja\/71-seconds-to-build-your-free-custom-webhook-illustrated-step-by-step-7a09b9e240ba\">the next article<\/a> 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.<\/p>\n<p id=\"8346\" class=\"graf graf--p graf-after--p graf--trailing\">You can find the <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/gitlab.com\/ninjayoto\/my-periodic-jobs\/tree\/master\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/gitlab.com\/ninjayoto\/my-periodic-jobs\/tree\/master\">sample code here<\/a>, and you can read the <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/gitlab.com\/ninjayoto\/my-periodic-jobs\/-\/jobs\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/gitlab.com\/ninjayoto\/my-periodic-jobs\/-\/jobs\">build logs here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to get GitLab to do periodic jobs for you in under a\u00a0minute click on New schedule\u00a0button [Unedited] What would technology be without a computer doing periodic work? Whether it\u2019s 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,12],"tags":[],"class_list":["post-3233","post","type-post","status-publish","format-standard","hentry","category-fcc","category-how-to"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"featured_image_urls_v2":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","RoboGalleryMansoryImagesCenter":"","RoboGalleryPreload":"","1536x1536":"","2048x2048":""},"post_excerpt_stackable_v2":"<p>How to get GitLab to do periodic jobs for you in under a\u00a0minute click on New schedule\u00a0button [Unedited] What would technology be without a computer doing periodic work? Whether it\u2019s 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\u200a\u2014\u200aand no frameworks, no server or docker configuration, no Raspberry Pi, no AWS and no tests! To make the example as universal as possible, we will only use 2 command lines: one&hellip;<\/p>\n","category_list_v2":"<a href=\"https:\/\/yyc.ninja\/index.php\/category\/how-to\/fcc\/\" rel=\"category tag\">Free Code Camp Articles<\/a>, <a href=\"https:\/\/yyc.ninja\/index.php\/category\/how-to\/\" rel=\"category tag\">How To Ninja<\/a>","author_info_v2":{"name":"YYC Ninja","url":"https:\/\/yyc.ninja\/index.php\/author\/admin\/"},"comments_num_v2":"0 comments","_links":{"self":[{"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/posts\/3233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/comments?post=3233"}],"version-history":[{"count":2,"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/posts\/3233\/revisions"}],"predecessor-version":[{"id":3292,"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/posts\/3233\/revisions\/3292"}],"wp:attachment":[{"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/media?parent=3233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/categories?post=3233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yyc.ninja\/index.php\/wp-json\/wp\/v2\/tags?post=3233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}