Deploy to Production with CI/CD
You’ve completed the first two stages of your CI/CD pipeline. The pipeline stops at integration testing intentionally to simulate an approval process before actually deploying to production. At the moment, the DreamHouse app is deployed in an ephemeral scratch org where your team can log into it for functional testing and review.
After you review the app in the scratch org, you switch back to GitLab where you click a button to continue the pipeline to install the package into your Trailhead Playground. Just like the other scratch orgs, when you approve the deploy stage, the integration testing scratch org is deleted as it is no longer needed.
Let’s review the current commit.
- Log in to https://gitlab.com if you’re not already there.
- Click the Projects dropdown and search for
dreamhouseto find your cloned repository, and select DreamHouse-sfdx.
- Click CI / CD then Pipelines.
- If your pipeline is still running, wait for it to complete. If successful, you should see a green checkmark with the status passed. If unsuccessful, you should see a red x with the status failed. Click the status of the latest pipeline to see more details.
- Click integration-testing to see that job's log.
- Scroll to the bottom of the job log to find the output of the
sfdx force:user:displaycommand. Note the Instance Url, Username, and Password displayed in the log output. You use these credentials to log in to the scratch org to review the DreamHouse app at this stage of the pipeline.
- Open an incognito window in your favorite web browser and navigate to the website indicated by the Instance Url listed in the job log. Enter the Username and Password credentials for the scratch org listed in the job log, then click Log In to Sandbox.
to open the App Launcher, then click DreamHouse.
- Click Property Finder. Notice there is sample data already imported. This is because the integration-testing job ran the
force:data:tree:importcommands to configure the scratch org for testing. How convenient!
- Explore the DreamHouse app.
- After you’re satisfied that the DreamHouse app is functioning as desired, close your incognito browser session and return to your GitLab project's pipeline page.
- From the latest pipeline, click the Play button on the app-deploy job. This starts the deployment stage.
- Click app-deploy to see that job's log. It can take a few minutes for the package install request to complete.
When completed, you get a glorious message, “Job succeeded”.
It's time to see the deployed changes.
- At the bottom of this step, click Launch to open your Trailhead Playground in a new browser tab.
- Click to open the App Launcher, then click DreamHouse. This step confirms you have successfully deployed the change to production in your Trailhead Playground. Once, there was no DreamHouse in your Trailhead Playground. Now, it’s there. Not by magic, but by CI/CD!
- Click Property Finder. Notice there is no sample data. This is because for production deployments you often don't want test data to automatically be inserted in the org each time a deployment occurs or a new package version is installed.
Now that DreamHouse is deployed, the next step is to repeat the development workflow: commit new changes to your Git repository and push them to GitLab to automatically re-trigger the pipeline. You have the opportunity to review the updated app and then approve deployment of those changes like you did during the first go-around.
After successfully deploying the application a second time, you will have completed setting up an automated CI/CD pipeline for application development using Salesforce DX within a Trailhead Playground. We’re almost there. Let’s do this.
- GitLab: Pipelines Introduction