{"id":4001,"date":"2019-02-15T12:22:04","date_gmt":"2019-02-15T12:22:04","guid":{"rendered":"https:\/\/cloudkul.com\/blog\/?p=4001"},"modified":"2023-09-07T09:42:36","modified_gmt":"2023-09-07T09:42:36","slug":"ci-cd-in-salesforce-dx-using-gitlab","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/","title":{"rendered":"How to start the CI\/CD in Salesforce DX using Gitlab"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Prerequisite For CI\/CD Implimentatation In Salesfroce:<\/h3>\n\n\n\n<ul>\n<li>&nbsp;Salesforce production org<\/li>\n\n\n\n<li>Connected app\/Consumer key<\/li>\n\n\n\n<li>Gitlab server<\/li>\n\n\n\n<li>Gitlab-runner<\/li>\n\n\n\n<li>Metadata package ID<\/li>\n\n\n\n<li>Self-signed SSL certificate<\/li>\n<\/ul>\n\n\n\n<p>In this blog, we will learn how to implement CI\/CD with SFDX using GitLab. To start CI\/CD in salesforce DX, we required a connected app for JWT-based authentication to our Salesforce Org. We can create a connected app in our Salesforce Org.<\/p>\n\n\n\n<p>To create a connected app in your org, follow the official Salesforce DX Developer Guide <a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.sfdx_dev.meta\/sfdx_dev\/sfdx_dev_auth_connected_app.htm\">link<\/a> :<\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\">After creating a connected app we can test our connection with our packaging org <\/span><span style=\"font-family: Liberation Serif, serif\">by running the command <\/span><span style=\"font-family: Liberation Serif, serif\">with the below-mentioned<\/span><span style=\"font-family: Liberation Serif, serif\">&nbsp;parameters.<\/span><\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\"><b>Packaging_Org_CONSUMER_KEY&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (Client ID)<\/b><\/span><\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\"><b>Packging_Org_USERNAME&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(User name of your org)<\/b><\/span><\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\"><b>JWT_KEY_FILE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/b><\/span><span style=\"font-family: Liberation Serif, serif\"><b>(Self-signed Key)<\/b><\/span><span style=\"font-family: Liberation Serif, serif\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\"><b>&#8220;sfdx force:auth:jwt:grant &#8211;clientid ${Packaging_Org_CONSUMER_KEY} &#8211;username ${Packging_Org_USERNAME} \\ &#8211;jwtkeyfile ${JWT_KEY_FILE} &#8211;setdefaultdevhubusername&#8221;<\/b><\/span><\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\"><span lang=\"en-IN\">After creating a connected app we required a <\/span><span lang=\"en-IN\">script <\/span><span lang=\"en-IN\">with SFDX commands <\/span><span lang=\"en-IN\">to start a pipeline <\/span><span lang=\"en-IN\">written in YAML <\/span><span lang=\"en-IN\">with the name<\/span> <span lang=\"en-IN\"><b>.gitlab-ci.yml. <\/b><\/span><span lang=\"en-IN\">B<\/span><span lang=\"en-IN\">a<\/span><span lang=\"en-IN\">sicaly a .gitlab-ci.yml file contains three jobs like Build,Test and deploy.<\/span><\/span><\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\"><span lang=\"en-IN\">In this script, we will <\/span><span lang=\"en-IN\">write our <\/span><span lang=\"en-IN\">sfdx commands <\/span>in the script section as<span lang=\"en-IN\"> per our production requirement<\/span><span lang=\"en-IN\"> to start continuous integration on salesforce. <\/span><span lang=\"en-IN\">As per our production requirement, I have created a script to test, deploy and release the salesforce <\/span><span lang=\"en-IN\">app<\/span><span lang=\"en-IN\"> versions. <\/span><\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong><span style=\"font-family: Liberation Serif, serif\"><span lang=\"en-IN\">Content of .gitlab-ci.yml is here:<\/span><\/span><\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">stages:\n - test\n - deploy\n\n\ntest:\n  stage: test\n  script:\n\n    - sfdx force:auth:jwt:grant --clientid ${Pack_Org_CONSUMER_KEY} --username ${Pack_Org_USERNAME} --jwtkeyfile ${Pack_Org_JWT_KEY_FILE}\n    - sfdx force:source:convert --outputdir ..\/mdipkg\/ --packagename \"your package name\"\n    - sfdx force:mdapi:deploy --deploydir ..\/mdipkg\/ --targetusername ${Pack_Org_USERNAME} -w -1\n    - sfdx force:mdapi:deploy:report\n    - sfdx force:apex:test:run -l RunLocalTests -d \/home\/gitlab-runner\/builds\/cd83014f\/0\/salesforce\/mdipkg\/classes -c -r human -u ${Pack_Org_USERNAME} -w 5\n\n  only:\n    - staging\n    - master\n  tags:\n    - your pipeline tag\n    - your pipeline tag\n\nbeta-release:\n  stage: deploy\n  script:\n    - a=$(git log -1 --pretty=%B)\n    - b=$(echo $a | cut -d \" \" -f 3 |grep -oE \"[0-9]{1,3}.?[0-9]{1,3}\")\n    - echo $b\n    - sfdx force:auth:jwt:grant --clientid ${Pack_Org_CONSUMER_KEY} --username ${Pack_Org_USERNAME} --jwtkeyfile ${Pack_Org_JWT_KEY_FILE}\n    - a=$(sfdx force:package1:version:create --packageid ${METADATAPACKAGEID} --name \"your package name\" -v $b -u ${Pack_Org_USERNAME} -w 5 --json | python -c \"import sys, json; print json.load(sys.stdin)['result']['Id']\")\n    - sfdx force:package1:version:create:get -i $a -u ${Pack_Org_USERNAME}\n  only:\n    - staging\n  tags:\n    - your pipeline tags\n    - your pipeline tags\n\nmanaged-release:\n  stage: deploy\n  script:\n    - sfdx force:auth:jwt:grant --clientid ${Pack_Org_CONSUMER_KEY} --username ${Pack_Org_USERNAME} --jwtkeyfile ${Pack_Org_JWT_KEY_FILE}\n    - a=$(sfdx force:package1:version:create --packageid ${METADATAPACKAGEID} --name \"your package name\" -u ${Pack_Org_USERNAME}  --managedreleased -w 5 --json | python -c \"import sys, json; print json.load(sys.stdin)['result']['Id']\")\n    - sfdx force:package1:version:create:get -i $a -u ${Pack_Org_USERNAME}\n  only:\n    - master\n  tags:\n    - your pipeline tags\n    - your pipeline tags\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Let&#8217;s know how the Script is working :<\/strong><\/h3>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\">In the above script, I have created three jobs, in the first job <strong>test,<\/strong> I am running the command &#8220;<strong>sfdx force:auth:jwt:grant&#8221;<\/strong>&nbsp;to connect the production org.<\/span><\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\">Then converted sfdx source code to mdapi format using the command &#8220;<strong>sfdx force:sourc<\/strong>e<strong>:<\/strong><strong>convert&#8221;<\/strong><\/span><\/p>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\">Then deployed the project to the production org by running the command &#8220;<strong>sfdx<\/strong><strong> force:mdapi<\/strong><strong>:<\/strong><strong>deploy&#8221;&nbsp; <\/strong>after deployment, I am running apex test command &#8220;<\/span><span style=\"font-family: Liberation Serif, serif\"><b><strong>sfdx force:apex:test:run&#8221;<\/strong><\/b><\/span><span style=\"font-family: Liberation Serif, serif\">&nbsp;to check the code coverage. <\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Create a beta package:<\/strong><\/h3>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\">In the second job<b> beta-release<\/b> first connects to the salesforce Org and runs &#8220;<\/span><span style=\"font-family: Liberation Serif, serif\"><b><strong>sfdx force:package1:version:create&#8221; <\/strong><\/b><\/span><span style=\"font-family: Liberation Serif, serif\">command to release the beta version of the salesforce package which I deployed in my first job.<\/span><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Create a managed package:<\/strong><\/h3>\n\n\n\n<p><span style=\"font-family: Liberation Serif, serif\">In the third job, the last job named managed release again runs &#8220;<b><strong>sfdx force:package1:version:create&#8221;<\/strong><\/b> command with the parameter&nbsp;<strong> &#8220;-<samp class=\"codeph nolang\">-managedreleased&#8221; <\/samp><\/strong><samp class=\"codeph nolang\">to create a managed package.<\/samp><\/span><\/p>\n\n\n\n<p>If you have any queries, you can ask in the comment box.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisite For CI\/CD Implimentatation In Salesfroce: In this blog, we will learn how to implement <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[86,341,182],"tags":[206,171,170,861,53,862,208,207],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to start the CI\/CD in Salesforce DX using Gitlab - Cloudkul<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to start the CI\/CD in Salesforce DX using Gitlab - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"Prerequisite For CI\/CD Implimentatation In Salesfroce: In this blog, we will learn how to implement [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-15T12:22:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-09-07T09:42:36+00:00\" \/>\n<meta name=\"author\" content=\"gajendra nath\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/\",\"name\":\"How to start the CI\/CD in Salesforce DX using Gitlab - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2019-02-15T12:22:04+00:00\",\"dateModified\":\"2023-09-07T09:42:36+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/3232dccbd607c3019393e41541357404\"},\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to start the CI\/CD in Salesforce DX using Gitlab\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/3232dccbd607c3019393e41541357404\",\"name\":\"gajendra nath\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6a5ebac9203a3f62a79f03c685839cbf?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6a5ebac9203a3f62a79f03c685839cbf?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"gajendra nath\"},\"url\":\"https:\/\/cloudkul.com\/blog\/author\/gajendra-nath921\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to start the CI\/CD in Salesforce DX using Gitlab - Cloudkul","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/","og_locale":"en_US","og_type":"article","og_title":"How to start the CI\/CD in Salesforce DX using Gitlab - Cloudkul","og_description":"Prerequisite For CI\/CD Implimentatation In Salesfroce: In this blog, we will learn how to implement [...]","og_url":"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/","og_site_name":"Cloudkul","article_published_time":"2019-02-15T12:22:04+00:00","article_modified_time":"2023-09-07T09:42:36+00:00","author":"gajendra nath","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/","url":"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/","name":"How to start the CI\/CD in Salesforce DX using Gitlab - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2019-02-15T12:22:04+00:00","dateModified":"2023-09-07T09:42:36+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/3232dccbd607c3019393e41541357404"},"breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/ci-cd-in-salesforce-dx-using-gitlab\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to start the CI\/CD in Salesforce DX using Gitlab"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/3232dccbd607c3019393e41541357404","name":"gajendra nath","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6a5ebac9203a3f62a79f03c685839cbf?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6a5ebac9203a3f62a79f03c685839cbf?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"gajendra nath"},"url":"https:\/\/cloudkul.com\/blog\/author\/gajendra-nath921\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/4001"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=4001"}],"version-history":[{"count":32,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/4001\/revisions"}],"predecessor-version":[{"id":16567,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/4001\/revisions\/16567"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=4001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=4001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=4001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}