{"id":96630,"date":"2023-04-28T10:07:37","date_gmt":"2023-04-28T10:07:37","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=96630"},"modified":"2023-04-28T21:01:58","modified_gmt":"2023-04-28T21:01:58","slug":"introduction-to-using-bitbucket-and-ci-cd-for-your-app","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/devops\/ci-cd\/introduction-to-using-bitbucket-and-ci-cd-for-your-app\/","title":{"rendered":"Introduction to Using Bitbucket and CI\/CD for Your App"},"content":{"rendered":"<p>If you have been in the DevOps space, you should know about version control and must have worked with 0ne. But, have you heard of BitBucket? No? Well, this tutorial is for you.<\/p>\n<p><a href=\"https:\/\/bitbucket.org\/product\/guides\/basics\/bitbucket-interface\">Bitbucket<\/a> is a web-based platform that provides hosting services for version control repositories, specifically for source code and development projects. It offers support for two different version control systems: <a href=\"https:\/\/www.mercurial-scm.org\/\">Mercurial<\/a> and <a href=\"https:\/\/git-scm.com\/\">Git<\/a>. It is owned by <a href=\"https:\/\/www.atlassian.com\/\">Atlassian<\/a> and used for source code and development projects that use either <a href=\"https:\/\/www.mercurial-scm.org\/\">Mercurial<\/a> or <a href=\"https:\/\/git-scm.com\/\">Git<\/a> version control systems. It provides a centralized location for storing and managing code, facilitates team collaboration and version control, and includes features such as pull requests, code reviews, and issue tracking. Bitbucket is widely used by software development teams for both personal and enterprise projects.<\/p>\n<p>Bitbucket integrates well with many third-party continuous integrations (CI) tools, including Jenkins, <a href=\"https:\/\/docs.travis-ci.com\/\">Travis CI<\/a>, <a href=\"https:\/\/circleci.com\/docs\/\">CircleCI<\/a>, <a href=\"https:\/\/confluence.atlassian.com\/bamboo\/getting-started-with-bamboo-289277283.html\">Bamboo<\/a>, and more. This integration allows developers to automate the build, test, and deployment processes for their software projects, making it easier to identify and resolve bugs and deliver high-quality software more quickly. Bitbucket provides a variety of APIs and integrations that allow developers to connect it with other tools and systems, including issue trackers, chat apps, and other development and collaboration tools.<\/p>\n<p>This tutorial \u200cwill teach you how to get started with Bitbucket. You will start with learning how to push an HTML project to a Bitbucket repository, configure Bitbucket pages for that respository so it can be viewed over the web browser, create and push a <code>VueJS<\/code> project to the same Bitbucket repository and then see how to configure CI\/CD workflows with <code>CircleCI<\/code> for that Bitbucket repository.<\/p>\n<p>In this article I am going to go through the follow steps to demonstrate using Bitbucket in your projects<\/p>\n<ul>\n<li>Prerequisites<\/li>\n<li>Initializing a Hello_World project.<\/li>\n<li>Creating a Bitbucket workspace and repository.<\/li>\n<li>Pushing your code to your Bitbucket repository.<\/li>\n<li>Hosting repository with Bitbucket pages.<\/li>\n<li>Using a third-party CI tool with Bitbucket.<\/li>\n<\/ul>\n<h2>Prerequisites<\/h2>\n<p>These are the things you will need to have (or expect to get if you want to follow along with the examples in this article)<\/p>\n<ul>\n<li>This tutorial uses a Linux machine with An <a href=\"https:\/\/www.omgubuntu.co.uk\/2022\/01\/ubuntu-22-04-release-features\">Ubuntu 22.04 LTS<\/a> OS. Every other OS works fine.<\/li>\n<li>A text editor (E.g VScode).<\/li>\n<li>A Bitbucket Cloud account. You can register <a href=\"https:\/\/www.atlassian.com\/software\/bitbucket\/bundle\">here<\/a> if you don\u2019t have one.<\/li>\n<li>An Atlassian account. If you don\u2019t have one, sign up for a free <a href=\"https:\/\/id.atlassian.com\/signup?application=mac&amp;continue=https:\/\/my.atlassian.com\">Atlassian account<\/a> first.<\/li>\n<li><a href=\"https:\/\/git-scm.com\/\">Git<\/a> installed locally on your machine, otherwise, you can follow this <a href=\"https:\/\/git-scm.com\/book\/en\/v2\/Getting-Started-Installing-Git\">guide<\/a> to get it installed depending on your OS.<\/li>\n<li>Circle CI account created with your Atlassian Bitbucket account<\/li>\n<\/ul>\n<h2>Initializing a Hello_World project<\/h2>\n<p>Prior to getting started with Bitbucket, you\u2019ll need to first have a project to work with. For demo and simplicity&#8217;s sake, you will create a project that simply outputs \u201cHello World\u201d to the browser.<\/p>\n<p>Create a project directory to store the files for the <code>hello_world<\/code> project. You can name this directory whatever you like &#8211; this tutorial uses <code>hello_world<\/code>.<\/p>\n<pre class=\"\">mkdir hello_world #creates the hello_world directory \r\n\r\ncd hello_world #goes into the hello_world directory \r\n\r\ncode . #opens up the hello_world directory via your \r\n       #default code editor<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1406\" height=\"158\" class=\"wp-image-96631\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-1.jpeg\" \/><\/p>\n<p><strong>Fig 1: Creating project directory \u201chello_world\u201d<\/strong><\/p>\n<p>Create an <code>index.html<\/code> file and paste in the code snippet below:<\/p>\n<pre class=\"lang:none theme:none\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=\"UTF-8\"&gt;\r\n    &lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"&gt;\r\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\r\n    &lt;title&gt;Bitcket App&lt;\/title&gt;\r\n    &lt;!-- Google fonts --&gt;\r\n    &lt;link rel=\"preconnect\" href=\"https:\/\/fonts.googleapis.com\"&gt;\r\n    &lt;link rel=\"preconnect\" href=\"https:\/\/fonts.gstatic.com\" crossorigin&gt;\r\n    &lt;link href=\"https:\/\/fonts.googleapis.com\/css2?family=IBM+Plex+Sans:wght@100&amp;display=swap\" rel=\"stylesheet\"&gt;\r\n    &lt;!-- Internal styles --&gt;\r\n    &lt;style&gt;\r\n        * {padding: 0; margin: 0; box-sizing: border-box;}\r\n          body {background-color: hsl(46, 100%, 50%);  \r\n          Font-family:'IBM Plex Sans', sans-serif; margin: \r\n          60px; display: flex; justify-content: center; \r\n          align-items: center;}\r\n        h1   {color: hsl(0, 4%, 10%); text-align: center;}\r\n        div { border: 5px solid hsl(318, 73%, 22%); width: 500px;\r\n              margin: 0 auto; padding: 10px;}\r\n    &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n    &lt;div&gt;\r\n        &lt;h1&gt;Hello World&lt;\/h1&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/body&gt;<\/pre>\n<p>When you view this over a web browser, this is how the web page will look like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"394\" class=\"wp-image-96632\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-2.jpeg\" \/><\/p>\n<p><strong>Fig 2: Viewing hello_world project over a web browser<\/strong><\/p>\n<p>The output above simply displays <code>Hello World<\/code> to the browser.<\/p>\n<h2>Creating a Bitbucket Workspace and Repository<\/h2>\n<p>Just like GitHub, you need to have a repository to house the application you\u2019d like to save on Bitbucket. If you are logging in to Bitbucket for the first time, you will be asked to first create a workspace.<\/p>\n<p>A Bitbucket workspace is a container for projects and repositories in Bitbucket, where users can store, manage, and collaborate on their source code. It allows teams to organise their work, assign access permissions to different users, and track changes to code in a centralised location. A workspace can contain multiple repositories, each with its own set of files and folders.<\/p>\n<p>Be sure to <em>click<\/em> on the <code>create workspace<\/code> button to create your Bitbucket workspace, just like what the output below does:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1394\" height=\"1174\" class=\"wp-image-96633\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-3.jpeg\" \/><\/p>\n<p><strong>Fig 3: Initializing creating a bit bucket workspace<\/strong><\/p>\n<p>A new page will show up asking you to add the name of your workspace. This tutorial uses <code>my-helloworldworkspace<\/code> as the name of the workspace. You can name yours whatever you like. Additionally, you have the option of making this workspace public or private. In this tutorial, you\u2019ll on-check the checkbox to enable the workspace to be public as shown in the output below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1272\" height=\"1221\" class=\"wp-image-96634\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-4.jpeg\" \/><\/p>\n<p><strong>Fig 4: Creating a Bitbucket workspace<\/strong><\/p>\n<p>Once you have created your workspace, you will be directed to your Bitbucket dashboard.<\/p>\n<p>This dashboard provides a centralized view of your repositories, projects, pull requests, issues, and more. It also allows you to manage your code, collaborate with others, and track the progress of your development projects.<\/p>\n<p>To create a repository, <em>click <\/em>on the <code>create<\/code> button on the navigation menu and <em>select <\/em><code>Repository<\/code> from the drop-down menu. This will initialize the process of creating a Bitbucket repository in your current workspace:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"598\" class=\"wp-image-96635\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-5.jpeg\" \/><\/p>\n<p><strong>Fig 5: Initialising creating a Bitbucket repository<\/strong><\/p>\n<p>The page will then redirect to where you\u2019ll need to provide some information about the repository you are trying to create which is as follows:<\/p>\n<ul>\n<li><strong>Workspace<\/strong>: This field will be automatically populated for you if you need to select a different workspace <em>click<\/em> on the dropdown icon.<\/li>\n<li><strong>Project name<\/strong>: Projects are a way to organize and manage repositories within a Bitbucket workspace. Provide a project name &#8211; this tutorial uses a project name <em>First-bitbucket-project<\/em>.<\/li>\n<li><strong>Repository name<\/strong>: Give your repository a name, this tutorial sets the repository name to &#8211; <em>hello-world<\/em>.<\/li>\n<li><strong>Access level<\/strong>: This field requires you to either make your repository private or public. This tutorial sets this field to &#8211; <em>public<\/em>.<\/li>\n<li><strong>Include a README<\/strong>: Just like GitHub, you have the option to create a <code>ReadMe<\/code> as you create your repository. This tutorial sets this field to <em>Yes<\/em>.<\/li>\n<li><strong>Default branch name<\/strong>: This field requires you to specify the default branch you\u2019d like to push your code to. This tutorial selects the main branch as the default branch.<\/li>\n<li><strong>Include .gitignore<\/strong>: This field asks you if you\u2019d like to add a <code>*.gitignore*<\/code> file to your repository, this tutorial selects <em>Yes<\/em>.<\/li>\n<\/ul>\n<p>You have the option to add a description and select the language your project comprised of. These settings are located in the <code>advanced settings<\/code> option.<\/p>\n<p>Go ahead and create this repository. This should take less than a minute:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1463\" height=\"1170\" class=\"wp-image-96636\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-6.jpeg\" \/><\/p>\n<p><strong>Fig 6: Creating a Bitbucket repository<\/strong><\/p>\n<p>Once your repository has been created successfully, you should see your repository presented to you on your Bitbucket dashboard like the output below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"832\" class=\"wp-image-96637\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-7.jpeg\" \/><\/p>\n<p><strong>Fig 7: Viewing Bitbucket repository<\/strong><\/p>\n<h2>Pushing your code to your Bitbucket repository<\/h2>\n<p>Since Bitbucket supports the Git version control system, you can upload and transfer the code from your local machine up to your Bitbucket remote repository using Git commands.<\/p>\n<p>Open up your project directory via a terminal or command prompt and execute the following Git commands to commit your changes and push your project up to your Bitbucket repository.<\/p>\n<p>First, execute the command below to initialize a new Git repository in the current directory, This command will create a new directory named <code>\".git\"<\/code> within the current directory, which contains all the necessary metadata and objects to manage version control for the project:<\/p>\n<pre class=\"lang:none theme:none\">git init<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1935\" height=\"476\" class=\"wp-image-96638\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-8.jpeg\" \/><\/p>\n<p><strong>Fig 8: Initialising a new Git repository<\/strong><\/p>\n<p>Display the current status of the local repository, including information about changed files that have not yet been committed to the repository, untracked files, and the current branch using the following command:<\/p>\n<pre class=\"lang:none theme:none\">git status<\/pre>\n<p>From the output below, you can see that you are on the master branch and haven\u2019t made any commits yet.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1526\" height=\"409\" class=\"wp-image-96639\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-9.jpeg\" \/><\/p>\n<p><strong>Fig 9: Viewing current branch, commits and untracked files<\/strong><\/p>\n<p>Now execute the following Git command to track the files in your current directory. This prepares them to be committed to the Git repository:<\/p>\n<pre class=\"lang:none theme:none\">git add . <\/pre>\n<p>Record changes to the local repository by specifying <code>commit<\/code>, which describes the changes being committed using the following Git command:<\/p>\n<pre class=\"lang:none theme:none\">git commit -m \"my first commit\"<\/pre>\n<p>The commit message provides context and helps to understand the purpose of the changes.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1729\" height=\"191\" class=\"wp-image-96640\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-10.jpeg\" \/><\/p>\n<p><strong>Fig 10: Making a commit message<\/strong><\/p>\n<p>Since you already have the <code>Main<\/code> branch as your default branch for your BitBucket remote repository, execute the Git command below to rename the current branch to <code>\"main\"<\/code>.<\/p>\n<p>The <code>\"-M\"<\/code> option specifies that it&#8217;s a branch rename operation.<\/p>\n<p>This can be useful if you want to change the name of your branch to better reflect the work you&#8217;re doing, or to align with best practices or conventions within your organisation.<\/p>\n<pre class=\"lang:none theme:none\">git branch -M main<\/pre>\n<p>Create a new remote named <em>origin<\/em> and set its URL to a specified URL using the Git command below. This allows you to push and pull changes from the remote repository located at the specified URL, which in this case is your repository on Bitbucket.<\/p>\n<pre class=\"lang:none theme:none\">git remote add origin \"YOUR_BITBUCKET_REPOSITORY_HERE\"<\/pre>\n<p>To get the URL of your Bitbucket repository, <em>Click<\/em> on the <code>clone<\/code> button from the top right side, and copy the URL after the <code>`git clone`<\/code> command highlighted below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2500\" height=\"922\" class=\"wp-image-96641\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-11.png\" \/><\/p>\n<p><strong>Fig 11: Copying Bitbucket repository URL<\/strong><\/p>\n<p>Since you allowed Bitbucket to add a <code>ReadME<\/code> and a<em> .<\/em><code>gitignore<\/code> file while creating your repository, you\u2019ll need to execute the following Git <code>pull<\/code> command to fetch and download the content from the remote repository and merge it with your local repository:<\/p>\n<pre class=\"lang:none theme:none\">git pull --rebase origin main<\/pre>\n<p>You should have the <code>ReadME<\/code> and the <code>.gitignore <\/code>file as shown in the below screenshot:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"914\" height=\"221\" class=\"wp-image-96642\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-12.jpeg\" \/><\/p>\n<p><strong>Fig 12: Viewing pulled files from remote Bitbucket repository<\/strong><\/p>\n<p>Create an App password on your Bitbucket account that you will use when you want to push your code up to your Bitbucket repository. <em>Click<\/em> on your avatar from your repository page and select <code>personal settings<\/code> from the dropdown menu:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"834\" class=\"wp-image-96643\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-13.jpeg\" \/><\/p>\n<p><strong>Fig 13: Initialising creating an app password<\/strong><\/p>\n<p>The page will redirect to the personal settings page. On this page, <em>select<\/em> the <code>App passwords<\/code> tab from the left panel. A new screen will be shown to you, <em>click<\/em> on the <code>create app password<\/code> button to create an app password:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"710\" class=\"wp-image-96644\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-14.jpeg\" \/><\/p>\n<p><strong>Fig 14: Creating app password<\/strong><\/p>\n<p>Give your app password a label (this tutorial uses <code>hello-world<\/code>) as the label, check all the check-boxes under the permissions section and <em>click<\/em> on the <code>create <\/code>button to create this password.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2000\" height=\"1192\" class=\"wp-image-96645\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-15.jpeg\" \/><\/p>\n<p><strong>Fig 15: Adding app-password label and permissions<\/strong><\/p>\n<p>A pop-up window will be shown to you containing your app password, copy the app password. Be sure to save this password somewhere you can access it, you will always need it whenever you try to push your code to any repository on your Bitbucket account.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1300\" height=\"617\" class=\"wp-image-96646\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-16.jpeg\" \/><\/p>\n<p><strong>Fig 16: Copying app password<\/strong><\/p>\n<p>Close the pop-up window once you have successfully copied the app password for your repository. You should be redirected to the below screen:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1828\" height=\"441\" class=\"wp-image-96647\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-17.jpeg\" \/><\/p>\n<p><strong>Fig 17: Viewing app-passwords<\/strong><\/p>\n<p>Last, execute the following Git command to push the local main branch to a remote repository. This command pushes the local main branch to a remote repository named <code>\"origin\"<\/code> with the <code>\"u\" <\/code>option set to track the remote branch as the local main branch.<\/p>\n<pre class=\"lang:none theme:none\">git push -u origin main<\/pre>\n<p>This command will prompt you to input your Bitbucket username and password. Make sure you provide the correct username and app password as your password.<\/p>\n<p>Once you have successfully pushed to your remote Bitbucket repository, all you now have to do is refresh your Bitbucket repository page. You should see the latest push:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1316\" height=\"408\" class=\"wp-image-96648\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-18.jpeg\" \/><\/p>\n<p><strong>Fig 18: Pushing commits to remote Bitbucket repository<\/strong><\/p>\n<p><strong>Hosting repository with Bitbucket pages<\/strong><\/p>\n<p>Bitbucket has a <code>pages<\/code> feature that allows you to host static websites directly from your Bitbucket repository. Bitbucket Pages provides a simple, fast, and flexible way for developers, teams, and organizations to create and host websites without the need for dedicated hosting infrastructure.<\/p>\n<p>First, you will need to rename your repository to include the following naming convention &#8211; <code>username\/workspaceID.bitbucket.io<\/code>. This is the required naming convention to setup pages for your Bitbucket repository.<\/p>\n<p>On your repository page, <em>select<\/em> the <code>repository settings<\/code> tab from the left panel:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"853\" class=\"wp-image-96649\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-19.jpeg\" \/><\/p>\n<p><strong>Fig 19: Viewing repository settings<\/strong><\/p>\n<p>Edit the name of your repository to follow the naming convention stated above and scroll down to the bottom of the page to save this setting:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"831\" class=\"wp-image-96650\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-20.jpeg\" \/><\/p>\n<p><strong>Fig 20: Renaming repository name<\/strong><\/p>\n<p>Once the change has been saved, navigate to the following web address over your preferred browser to see your static site:<\/p>\n<pre class=\"lang:none theme:none\">https:\/\/workspace_ID.bitbucket.io\r\nhttps:\/\/my-helloworldworkspace.bitbucket.io\/<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"328\" class=\"wp-image-96651\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-21.jpeg\" \/><\/p>\n<p><strong>Fig 21: Viewing repository<\/strong><\/p>\n<h2>Using a third-party CI tool with Bitbucket<\/h2>\n<p>As I mentioned earlier Bitbucket integrates very well with third-party continuous integration and delivery tools. For this tutorial, you\u2019ll be integrating Bitbucket with <a href=\"https:\/\/circleci.com\/\">Circle CI<\/a>.<\/p>\n<p>First, execute the Git command below to create an <a href=\"https:\/\/shannoncrabill.com\/blog\/git-orphan-branches\/\">orphan<\/a> branch &#8211; you can name this branch whatever you like. This tutorial uses <em>circle-ci<\/em> as the branch name. This branch will contain a VueJS project, this is the project we will be using for this demo. The reason you\u2019ll need to create this branch is that we only want to configure continuous integration and delivery for only the <code>circle-ci<\/code> branch.<\/p>\n<pre class=\"lang:none theme:none\">git checkout --orphan circle-ci\r\ngit rm -rf .<\/pre>\n<p>This will result in something like the following.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"1614\" height=\"265\" class=\"wp-image-96652\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-22.jpeg\" \/><\/strong><\/p>\n<p><strong>Fig 22: Checking out to orphan branch (circle-ci)<\/strong><\/p>\n<p>Create a VueJS project using the following command. This command creates a VueJS project using the <a href=\"https:\/\/vitejs.dev\/guide\/\">Vite<\/a> build tool.<\/p>\n<p>npm create vue@3<\/p>\n<p>This command outputs some questions, you\u2019ll provide the following answers:<\/p>\n<ul>\n<li><strong>Project name<\/strong>: <em>type<\/em> in (.) so it builds the project in the current directory. (<em>type in enter to continue<\/em>)<\/li>\n<li><strong>Package name<\/strong>: vue (<em>you can name it whatever you like<\/em>)<\/li>\n<li><strong><em>Add TypeScript?<\/em><\/strong><em> \u2026 No \/ Yes (NO is the default so, type enter<\/em>)<\/li>\n<li><strong>Add JSX Support?<\/strong> \u2026 No<\/li>\n<li><strong>Add Vue Router for Single Page Application development? <\/strong>\u2026 No<\/li>\n<li><strong>Add Pinia for state management?<\/strong> \u2026 No<\/li>\n<li><strong>Add Vitest for Unit Testing? <\/strong>\u2026 Yes (<em>Use your left-arrow key to select yes<\/em>)<\/li>\n<li><strong>Add an End-to-End Testing Solution?<\/strong> \u203a No<\/li>\n<li><strong>Add ESLint for code quality?<\/strong> \u2026 No<\/li>\n<\/ul>\n<p>Once the VueJS project has been created successfully, you should have the following output:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1346\" height=\"761\" class=\"wp-image-96653\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-23.jpeg\" \/><\/p>\n<p><strong>Fig 23: Creating VueJS project with Vite<\/strong><\/p>\n<p>Run the below command to install all the dependencies needed for the project:<\/p>\n<pre class=\"lang:none theme:none\">npm install<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1582\" height=\"359\" class=\"wp-image-96654\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-24.jpeg\" \/><\/p>\n<p><strong>Fig 24: Installing all project dependencies<\/strong><\/p>\n<p>Since you accepted to add Vitest for unit testing, you have an already configured example test in the project <code>src<\/code> folder, named <code>HelloWorld.spec.js<\/code>. This is the sample test we will instruct CircleCI to check for before pushing our code up to our Bitbucket repository:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"942\" class=\"wp-image-96655\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-25.jpeg\" \/><\/p>\n<p><strong>Fig 25: Viewing sample test (HelloWorld.spec.js)<\/strong><\/p>\n<p>Run the following command below to check if this test passes:<\/p>\n<pre class=\"lang:none theme:none\">npm run test:unit<\/pre>\n<p>If it passes you should have output similar to below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1545\" height=\"482\" class=\"wp-image-96656\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-26.jpeg\" \/><\/p>\n<p><strong>Fig 26: Viewing successful test<\/strong><\/p>\n<p>Create a folder in the current directory called <code>.circleci<\/code>, in there, <em>create<\/em> a file called <code>config.yml<\/code> This is the exact naming style for the CircleCI configuration file.<\/p>\n<p>Add the below code snippets:<\/p>\n<pre class=\"lang:none theme:none\">version: 4.0\r\njobs:\r\n  build:\r\n    working_directory: ~\/repo\r\n    branch: circle-ci\r\n    docker:\r\n      - image: cimg\/node:19.4.0\r\n    steps:\r\n      - checkout\r\n      - run:\r\n          name: update-npm\r\n          command: sudo npm install -g npm@latest\r\n      - restore_cache:\r\n          key: dependency-cache-{{ checksum \"package-lock.json\" }}\r\n      - run: \r\n          name: install-all-packages\r\n          command: npm install\r\n      - save_cache:\r\n          key: dependency-cache-{{ checksum \"package-lock.json\" }}\r\n          paths:\r\n           - .\/node_modules\r\n      - run: \r\n          name: run tests\r\n          command: npm run test:unit\r\n      - run:\r\n          name: generate static files #dist\r\n          command: |\r\n            npm run build\r\n            echo \"Pushed to Bitbucket\"<\/pre>\n<p>Now push your changes up to the <code>circle-ci<\/code> branch using the below commands:<\/p>\n<pre class=\"lang:none theme:none\">git add .\r\ngit commit -m 'first commit for the circle-ci branch'\r\n# you'll need to do this since your renamed your Bitbucket repository\r\ngit remote remove origin\r\n# Be sure to add your own repository url\r\ngit remote add origin \"git@bitbucket.org:my-helloworldworkspace\/my-helloworldworkspace.bitbucket.io.git\"\r\ngit push origin circle-ci<\/pre>\n<p>Once you have successfully pushed your code to the <em>circle-ci<\/em> branch, when you <em>select<\/em> the <em>Branches<\/em> tab from the left panel on your Bitbucket repository, you should see that you now have two branches. The <em>main<\/em> branch and the <em>circle-ci<\/em> branch:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"666\" class=\"wp-image-96657\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-27.jpeg\" \/><\/p>\n<p><strong>Fig 27: Viewing branches on Bitbucket repository<\/strong><\/p>\n<p><em>Select<\/em> the <code>Source<\/code> tab from the left panel to confirm that you also have the <code>circle-ci<\/code> branch created:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"856\" class=\"wp-image-96658\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-28.jpeg\" \/><\/p>\n<p><strong>Fig 28: Viewing branches on Bitbucket repository<\/strong><\/p>\n<p>Now you can view the code pushed by selecting <code>the circle-ci<\/code> branch, from the above image:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"862\" class=\"wp-image-96659\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-29.jpeg\" \/><\/p>\n<p><strong>Fig 29: Viewing source code on circle-ci branch<\/strong><\/p>\n<p>Since you are using <code>CircleCI<\/code> as the CI\/CD tool, you\u2019ll need to generate an <code>SSH<\/code> key pair and add the public key in your Bitbucket repository else your build will fail. To achieve this, <em>click<\/em> on your avatar and <em>select<\/em> the <code>personal settings<\/code> from the dropdown menu:<\/p>\n<p>Run the following command to generate a ssh key pair <code>-  ssh-keygen -t rsa -b 4096 -C YOUR_BITBUCKET_EMAIL<\/code><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"889\" class=\"wp-image-96660\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-30.jpeg\" \/><\/p>\n<p><strong>Fig 30: Selecting personal settings to add ssh key on bitbucket<\/strong><\/p>\n<p><em>Select<\/em> the <code>SSH keys<\/code> from the left panel and <em>click<\/em> on the <code>Add key<\/code> button:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"656\" class=\"wp-image-96661\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-31.jpeg\" \/><\/p>\n<p><strong>Fig 31: Initialising add ssh key on bitbucket<\/strong><\/p>\n<p>A pop-up window will be shown to you, input the name of the key as the label, add the public key and then <em>click<\/em> on the <code>Add key<\/code> button to add this key.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"911\" class=\"wp-image-96662\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-32.jpeg\" \/><\/p>\n<p><strong>Fig 32: Adding ssh key to Bitbucket (circle ci)<\/strong><\/p>\n<p>Head over to CircleCI and sign up with your Bitbucket account and be sure to <em>select<\/em> the Bitbucket workspace housing the repository you are trying to build with CircleCI:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1256\" height=\"1296\" class=\"wp-image-96663\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-33.jpeg\" \/><strong>Fig 33: Selecting Bitbucket workspace<\/strong><\/p>\n<p>Once you have selected your workspace you should be taken to your dashboard to set up a project. From your dashboard, <em>click<\/em> on the <code>Add project<\/code> button highlighted below, to add a project:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"729\" class=\"wp-image-96664\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-34.jpeg\" \/><\/p>\n<p><strong>Fig 34: Viewing CircleCI dashboard<\/strong><\/p>\n<p>Since CircleCI has access to your Bitbucket workspace, it will automatically output all the repositories you have on that workspace. In this case, the only repository available in the <code>my-helloworldworkspace<\/code> is <a href=\"http:\/\/my-helloworldworkspace.bitbucket.io\">my-helloworldworkspace.bitbucket.io<\/a>. So, <em>click<\/em> the <code>Set up project<\/code> button beside the repository to set up a CircleCI project for that repository:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"726\" class=\"wp-image-96665\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-35.jpeg\" \/><\/p>\n<p><strong>Fig 35: Setting up a CircleCI project<\/strong><\/p>\n<p>This will output a pop-up asking you to <em>select<\/em> the branch you would like to build, it also checks if there is a <code>.circleci<\/code><em>\/<\/em><code>config.yml<\/code> file available in that branch and if there\u2019s you\u2019ll have a green check mark indicating it has found <code>the .circleci\/config.yml<\/code> file , else it provides you with other options to create a <code>.circleci\/config.yml<\/code> file for it to use.<\/p>\n<p>Now <em>type<\/em> in <code>circle-ci <\/code>as the branch and <em>click<\/em> on the <code>Set up project<\/code> button to proceed:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"741\" class=\"wp-image-96666\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-36.jpeg\" \/><\/p>\n<p><strong>Fig 36: Selecting config.yml file for CircleCI<\/strong><\/p>\n<p>The page will then navigate to your dashboard for you to view your pipeline. The following output shows that the pipeline was successful:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"721\" class=\"wp-image-96667\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-37.jpeg\" \/><\/p>\n<p><strong>Fig 37: Viewing successful pipeline<\/strong><\/p>\n<p>If you also head to your Bitbucket branches page for your repository, you will see the below output showing that the build on CircleCI was successful:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"624\" class=\"wp-image-96668\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2023\/04\/word-image-96630-38.jpeg\" \/><\/p>\n<p><strong>Fig 38: viewing build on Bitbucket repository<\/strong><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>Bitbucket is as you have seen just like GitHub, you can do the basic things you do on GitHub on Bitbucket too. You have seen how to create a workspace, project, and repository on Bitbucket. You have also seen how to use Bitbucket pages to view your repositories over a browser and ultimately seen how to integrate Bitbucket with CircleCI.<\/p>\n<p>I believe you can agree with me that Bitbucket is easy to use out of the box just like GitHub. You can take a tour to test other Bitbucket features like <a href=\"https:\/\/support.atlassian.com\/bitbucket-cloud\/docs\/tutorial-learn-about-bitbucket-pull-requests\/\">pull requests<\/a>, <a href=\"https:\/\/support.atlassian.com\/bitbucket-cloud\/docs\/bitbucket-pipelines-configuration-reference\/\">Bitbucket pipelines<\/a>, and <a href=\"https:\/\/bitbucket.org\/product\/guides\/basics\/bitbucket-interface\">more<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you have been in the DevOps space, you should know about version control and must have worked with 0ne. But, have you heard of BitBucket? No? Well, this tutorial is for you. Bitbucket is a web-based platform that provides hosting services for version control repositories, specifically for source code and development projects. It offers&#8230;&hellip;<\/p>\n","protected":false},"author":341730,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143518,53],"tags":[],"coauthors":[158989],"class_list":["post-96630","post","type-post","status-publish","format-standard","hentry","category-ci-cd","category-featured"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/96630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/341730"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=96630"}],"version-history":[{"count":5,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/96630\/revisions"}],"predecessor-version":[{"id":96673,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/96630\/revisions\/96673"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=96630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=96630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=96630"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=96630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}