{"id":667,"date":"2022-08-09T21:53:04","date_gmt":"2022-08-09T20:53:04","guid":{"rendered":"http:\/\/192.168.1.213:8088\/?page_id=667"},"modified":"2022-08-10T13:37:34","modified_gmt":"2022-08-10T12:37:34","slug":"task-4-first-cicd-pipeline","status":"publish","type":"page","link":"http:\/\/192.168.1.213:8088\/gitlab-cicd-workshop\/task-4-first-cicd-pipeline\/","title":{"rendered":"Task 4: First CI\/CD pipeline"},"content":{"rendered":"\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t

\n\t\t\t\tTable of Contents\t\t\t<\/h4>\n\t\t\t\t\t<\/div>\n\t\t
\n\t\t\t
\n\t\t\t\t<\/i>\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t
Create the pipeline file<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

Alright! This is the moment we have been waiting for. Let’s build the first pipeline.<\/p>

Go to Repository > Files , Click on the + symbol and New File<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\"\"\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

A new window will open with an editor view. The new name of the file is: .gitlab-ci.yml\u00a0<\/strong><\/p>

Please copy and paste the filename. Yes, it is starting with a . (dot)<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\"\"\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\t\t

In the editor window, copy and paste the following content and submit the changes:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t

\n\t\t\t\t
\n\t\t\t
Content of the pipeline file<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\tworkflow:\n  rules:\n    - if: $CI_COMMIT_BRANCH != \"main\" && $CI_PIPELINE_SOURCE != \"merge_request_event\"      \n      when: never\n    - when: always\n\nstages:\n  - test_docker\n  - test_shell\n\nrun_test_docker:\n  stage: test_docker\n  tags:\n    - docker\n  script:\n    - echo $HOSTNAME\n    - echo \"I am a test output on a docker environment\"\n\nrun_test_shell:\n  stage: test_shell\n  tags:\n    - shell\n  script:\n    - echo $HOSTNAME\n    - echo \"I am a test output on a shell environment\"\n    - ansible --version\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-11bb744 elementor-widget elementor-widget-heading\" data-id=\"11bb744\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">Explanation<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-4101df1 elementor-widget elementor-widget-text-editor\" data-id=\"4101df1\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>What exactly are we doing here?!\u00a0<\/p><ul><li>First of all we are defining rules when the pipeline should be executed<ul><li>In this case when we are in the main branch and a merge request is created\u00a0<\/li><\/ul><\/li><li>We define stages for your pipeline<\/li><li>The first task is &#8220;run_test_docker&#8221; and this will be part of the &#8220;test_docker&#8221; stage<ul><li>The tag defines on which gitlab-runner it will be executed\u00a0<\/li><li>The script section defines which commands will be executed on the shell inside of the docker<\/li><\/ul><\/li><li>The next task run in the &#8220;test_shell&#8221; stage and runs on the shell gitlab-runner<\/li><\/ul><p>\u00a0<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a446ba2 elementor-widget elementor-widget-heading\" data-id=\"a446ba2\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">Check the pipeline execution<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f4ae271 elementor-widget elementor-widget-text-editor\" data-id=\"f4ae271\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Whenever you are submitting changes in the entire repository, the pipeline will be triggered! Let&#8217;s check the status of the pipeline execution. Click on <strong>CI\/CD<\/strong> and <strong>Pipelines\u00a0<\/strong>then click on the (hopefully\ud83d\ude09) passed pipeline execution.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8cf07ff elementor-widget elementor-widget-image\" data-id=\"8cf07ff\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-021.png\" data-elementor-open-lightbox=\"yes\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6Njg3LCJ1cmwiOiJodHRwOlwvXC8xOTIuMTY4LjEuMjEzOjgwODhcL3dwLWNvbnRlbnRcL3VwbG9hZHNcLzIwMjJcLzA4XC9naXRsYWItMDIxLnBuZyJ9\">\n\t\t\t\t\t\t\t<img decoding=\"async\" width=\"1864\" height=\"985\" src=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-021.png\" class=\"attachment-full size-full wp-image-687\" alt=\"\" srcset=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-021.png 1864w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-021-300x159.png 300w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-021-1024x541.png 1024w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-021-768x406.png 768w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-021-1536x812.png 1536w\" sizes=\"(max-width: 1864px) 100vw, 1864px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-879c47c elementor-widget elementor-widget-text-editor\" data-id=\"879c47c\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Click on each job to see what exactly has been executed in the each job:<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ed32150 elementor-widget elementor-widget-image\" data-id=\"ed32150\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-022.png\" data-elementor-open-lightbox=\"yes\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6Njg4LCJ1cmwiOiJodHRwOlwvXC8xOTIuMTY4LjEuMjEzOjgwODhcL3dwLWNvbnRlbnRcL3VwbG9hZHNcLzIwMjJcLzA4XC9naXRsYWItMDIyLnBuZyJ9\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"1866\" height=\"988\" src=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-022.png\" class=\"attachment-full size-full wp-image-688\" alt=\"\" srcset=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-022.png 1866w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-022-300x159.png 300w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-022-1024x542.png 1024w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-022-768x407.png 768w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-022-1536x813.png 1536w\" sizes=\"(max-width: 1866px) 100vw, 1866px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-63340cc elementor-widget elementor-widget-heading\" data-id=\"63340cc\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">Docker execution output<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2da8f20 elementor-widget elementor-widget-image\" data-id=\"2da8f20\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-023.png\" data-elementor-open-lightbox=\"yes\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6Njg5LCJ1cmwiOiJodHRwOlwvXC8xOTIuMTY4LjEuMjEzOjgwODhcL3dwLWNvbnRlbnRcL3VwbG9hZHNcLzIwMjJcLzA4XC9naXRsYWItMDIzLnBuZyJ9\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"1862\" height=\"986\" src=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-023.png\" class=\"attachment-full size-full wp-image-689\" alt=\"\" srcset=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-023.png 1862w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-023-300x159.png 300w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-023-1024x542.png 1024w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-023-768x407.png 768w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-023-1536x813.png 1536w\" sizes=\"(max-width: 1862px) 100vw, 1862px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2c16837 elementor-widget elementor-widget-heading\" data-id=\"2c16837\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">Shell execution output<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-30d6084 elementor-widget elementor-widget-image\" data-id=\"30d6084\" data-element_type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-024.png\" data-elementor-open-lightbox=\"yes\" data-e-action-hash=\"#elementor-action%3Aaction%3Dlightbox%26settings%3DeyJpZCI6NjkwLCJ1cmwiOiJodHRwOlwvXC8xOTIuMTY4LjEuMjEzOjgwODhcL3dwLWNvbnRlbnRcL3VwbG9hZHNcLzIwMjJcLzA4XC9naXRsYWItMDI0LnBuZyJ9\">\n\t\t\t\t\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"1865\" height=\"985\" src=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-024.png\" class=\"attachment-full size-full wp-image-690\" alt=\"\" srcset=\"http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-024.png 1865w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-024-300x158.png 300w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-024-1024x541.png 1024w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-024-768x406.png 768w, http:\/\/192.168.1.213:8088\/wp-content\/uploads\/2022\/08\/gitlab-024-1536x811.png 1536w\" sizes=\"(max-width: 1865px) 100vw, 1865px\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-844cd3b elementor-widget elementor-widget-text-editor\" data-id=\"844cd3b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Go back to CI\/CD and click on Editor. Try to experiment and get familiar with the syntax of the pipeline code.\u00a0<\/p><p>Try to do the following steps:<\/p><ul><li>Run &#8220;ansible &#8211;version&#8221; in the &#8220;test_docker&#8221; stage<\/li><li>Run wrong commands<\/li><li>Try to add more tasks per stage<\/li><li>Test\u00a0 <strong>before_script<\/strong> and <strong>after script<\/strong> in the tasks\u00a0<\/li><\/ul>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-0b0c222 elementor-widget elementor-widget-heading\" data-id=\"0b0c222\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h5 class=\"elementor-heading-title elementor-size-default\">References<\/h5>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9d4dc80 elementor-widget elementor-widget-text-editor\" data-id=\"9d4dc80\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p><span style=\"color: var( --e-global-color-text ); background-color: var( --e-global-color-6fbcf51 );\">As a command reference you can go to the following GitLab documentation:<\/span><\/p><ul><li>.gitlab-ci.yml command reference: <a href=\"https:\/\/docs.gitlab.com\/ee\/ci\/yaml\/\" rel=\"noopener\">https:\/\/docs.gitlab.com\/ee\/ci\/yaml\/<\/a><\/li><li>Official Template examples <a href=\"https:\/\/docs.gitlab.com\/ee\/ci\/examples\/\" rel=\"noopener\">https:\/\/docs.gitlab.com\/ee\/ci\/examples\/<\/a><\/li><\/ul>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d125a3d elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d125a3d\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f3fd90c\" data-id=\"f3fd90c\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-8da1c11 elementor-widget elementor-widget-html\" data-id=\"8da1c11\" data-element_type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<script type=\"text\/javascript\">\n(function($) {\n    $(window).load(function() {\n        $('.token.entity').each(function() {\n            var title = $(this).attr('title');\n            $(this).html(title);\n        })\n    });\n})(jQuery);\n<\/script>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Table of Contents Create the pipeline file Alright! This is the moment we have been waiting for. Let&#8217;s build the first pipeline. Go to Repository &gt; Files , Click on the + symbol and New File A new window will open with an editor view. The new name of the file is: .gitlab-ci.yml\u00a0 Please copy [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":538,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"class_list":["post-667","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/pages\/667"}],"collection":[{"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/comments?post=667"}],"version-history":[{"count":22,"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/pages\/667\/revisions"}],"predecessor-version":[{"id":896,"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/pages\/667\/revisions\/896"}],"up":[{"embeddable":true,"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/pages\/538"}],"wp:attachment":[{"href":"http:\/\/192.168.1.213:8088\/wp-json\/wp\/v2\/media?parent=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}