<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Omar Shabab on Medium]]></title>
        <description><![CDATA[Stories by Omar Shabab on Medium]]></description>
        <link>https://medium.com/@omar16100?source=rss-cde301d6a626------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MQQ_Gtaria5vWnzTV5Gd6g.jpeg</url>
            <title>Stories by Omar Shabab on Medium</title>
            <link>https://medium.com/@omar16100?source=rss-cde301d6a626------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:16:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@omar16100/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Trigger Bitbucket Pipeline Only If Certain Files Are Changed (With Google Cloud Functions)]]></title>
            <link>https://medium.com/@omar16100/trigger-bitbucket-pipeline-only-if-certain-files-are-changed-with-google-cloud-functions-22a726428143?source=rss-cde301d6a626------2</link>
            <guid isPermaLink="false">https://medium.com/p/22a726428143</guid>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[cicd]]></category>
            <dc:creator><![CDATA[Omar Shabab]]></dc:creator>
            <pubDate>Thu, 21 May 2020 02:25:37 GMT</pubDate>
            <atom:updated>2020-05-21T02:25:37.099Z</atom:updated>
            <content:encoded><![CDATA[<p><em>First appeared in </em><a href="https://omar.ai/posts/bitbucket_pipelines_custom_trigger/"><em>omar.ai</em></a>.</p><figure><img alt="Overview" src="https://cdn-images-1.medium.com/max/712/0*DxHuGfPZpvb4VuOn.png" /><figcaption>Overview of what you will do.</figcaption></figure><p>Having DevOps practices can make you really productive as a developer. It is a culture in an organization and there are countless tools we can use to implement such solutions.</p><p>In this article we will implement a Bitbucket CI/CD pipeline.</p><blockquote>Assumption : you have some familiarity with DevOps, CI/CD, Cloud Functions, Bitbucket and docker. If not, you may visit the <a href="#definitions">references</a>.</blockquote><h4>Scenerio</h4><p>You have multiple cloud functions in a repository and want an individual build-test-deployment option for each function.</p><figure><img alt="Screenshot of bitbucket repository" src="https://cdn-images-1.medium.com/max/264/0*tM95KOHC_A8izNFm.png" /></figure><blockquote>Note : these example functions are extended from the sample provided in GCP documentation.</blockquote><h4>Let’s say you have two functions which prints</h4><pre>Hello World!</pre><p>and</p><pre>Hello Mars!</pre><p>These functions are hosted in Bitbucket and initially you can deploy them from your local environment :</p><pre>gcloud functions deploy hello_world --allow-unauthenticated --runtime=python37 --memory=128MB --source hello_word/ --timeout=300 --trigger-http --entry-point=hello_world</pre><p>But this is not the ideal process. Solution is to use version control and automated build, test and deployment.</p><p>Below is a new feature for Bitbucket pipelines at the time of writing which triggers the pipeline when certain files are changed :</p><pre>condition:<br>    changesets:<br>        includePaths:<br>          - &quot;path/*&quot;</pre><h4>Hands-on</h4><h4>Steps</h4><ul><li>Create a service account in GCP</li><li>Export the service account credentials to Bitbucket and configure the bitbucket parameters</li><li>Setup Bitbucket pipelines</li></ul><h4>From GCP console</h4><ul><li>IAM &amp; Admin -&gt; Service Accounts -&gt; Create Service Account</li><li>Choose an appropriate name and click create</li><li>Select ‘Service Account User’ role</li><li>Click ‘Create Key’ and save the .json file. Finally, press ‘Done’ to proceed</li></ul><p>Your service account is created and you need to provide some permissions for the Bitbucket pipelines to work properly.</p><h4>From IAM &amp; Admin</h4><ul><li>Go to ‘Roles’</li><li>Select ‘Create Role’</li><li>Give suitable names ‘Title’ and ‘ID’</li><li>In ‘Add Permissions’ add ‘Cloud Functions Admin’ &amp; ‘Service Account User’</li><li>Click ‘Create’ and your custom role is created which needs to be attached to the service account</li><li>Go to ‘IAM’ and select your service account which was created earlier</li><li>Click inheritance and add the role to it</li></ul><p>Next up is configuring Bitbucket pipelines.</p><p>You will have to set up the environment variables first. We have to do this because hard-coding credentials is a bad practice.</p><p>Try to make the variables as verbose as possible, it helps when you have multi-environment variables. e.g. think if you had 10 functions from 10 different projects.</p><p>The following variables should be added.</p><pre>GCP_PROJECT_PROJECT_ID<br>GCP_PROJECT_PRIVATE_KEY_ID<br>GCP_PROJECT_PRIVATE_KEY<br>GCP_PROJECT_EMAIL<br>GCP_PROJECT_CLIENT_ID<br>GCP_PROJECT_CERT_URL<br>GCP_PROJECT_REGION</pre><p>Substitute the ‘PROJECT’ with your ‘project name’.</p><p>As this is a how-to guide, I will not be using multi-environment variables. The default naming is not changed.</p><h4>In Bitbucket repository</h4><ul><li>Go to ‘Repository Settings’ -&gt; ‘Repository variables’</li><li>If enabling pipelines is required, follow the steps</li><li>Commit the default pipeline provided which you are going to change soon</li><li>Add the above mentioned names. The values are from the service account credential file and the region is the one you are using</li></ul><p>Create a file named “sa-PROJECT.dist.json”. Where ‘sa’ stands for ‘service account’ and ‘PROJECT’ for ‘project name’.</p><p>Contents of the file is a copy of your credentials from the service account but with the environment variables.</p><pre>{<br>&quot;type&quot;: &quot;service_account&quot;,<br>&quot;project_id&quot;: &quot;$GCP_PROJECT_PROJECT_ID&quot;,<br>&quot;private_key_id&quot;: &quot;$GCP_PROJECT_PRIVATE_KEY_ID&quot;,<br>&quot;private_key&quot;: &quot;$GCP_PROJECT_PRIVATE_KEY&quot;,<br>&quot;client_email&quot;: &quot;$GCP_PROJECT_EMAIL&quot;,<br>&quot;client_id&quot;: &quot;$GCP_PROJECT_CLIENT_ID&quot;,<br>&quot;auth_uri&quot;: &quot;https://accounts.google.com/o/oauth2/auth&quot;,<br>&quot;token_uri&quot;: &quot;https://oauth2.googleapis.com/token&quot;,<br>&quot;auth_provider_x509_cert_url&quot;: &quot;https://www.googleapis.com/oauth2/v1/certs&quot;,<br>&quot;client_x509_cert_url&quot;: &quot;$GCP_PROJECT_CERT_URL&quot;<br>}</pre><h4>Now you will work with the bitbucket-pipelines.yml file</h4><blockquote><a href="https://bitbucket-pipelines.prod.public.atl-paas.net/validator">They have a sweet tool to validate your pipelines.</a></blockquote><p>bitbucket-pipelines.yml :</p><pre>pipelines:<br>  branches:<br>    master:<br>      - step:<br>          name: Deploy hello_world<br>#          deployment: test/ staging/ production<br>          image: google/cloud-sdk:234.0.0<br>          script:<br>              - apt-get update &amp;&amp; apt-get install -y gettext-base<br>              - envsubst &lt; sa-PROJECT.dist.json &gt; service-account.json<br>              - gcloud auth activate-service-account --key-file=service-account.json<br>              - gcloud functions deploy hello_world --runtime python37 --trigger-http --project $GCP_PROJECT_PROJECT_ID --region $GCP_PROJECT_REGION --source hello_world/<br>          condition:<br>              changesets:<br>                 includePaths:<br>                   - &quot;hello_world/*&quot;<br>      - step:<br>          name: Deploy hello_mars<br>#          deployment: test/ staging/ production<br>          image: google/cloud-sdk:234.0.0<br>          script:<br>              - apt-get update &amp;&amp; apt-get install -y gettext-base<br>              - envsubst &lt; sa-PROJECT.dist.json &gt; service-account.json<br>              - gcloud auth activate-service-account --key-file=service-account.json<br>              - gcloud functions deploy hello_mars --runtime python37 --trigger-http --project $GCP_PROJECT_PROJECT_ID --region $GCP_PROJECT_REGION --source hello_mars/<br>          condition:<br>              changesets:<br>                 includePaths:<br>                   - &quot;hello_mars/*&quot;</pre><p>You can find the code at this <a href="https://bitbucket.org/omar16100/bitbucket_pipelines_custom_trigger_cloud_functions/src/master/">Bitbucket repository</a>. And you can use it as template.</p><p>So now if you want to experiment you may modify ‘hello_mars’ only ‘hello mars’ will be deployed and vice versa.</p><p>And you are done triggering bitbucket pipelines when certain files are changed!</p><p>Thanks for reading!</p><blockquote>If you have any feedback, you may comment below or tweet <a href="https://twitter.com/omar161000">@omar161000</a>. Connect with me on <a href="https://www.linkedin.com/in/omar16100">Linkedin</a>.</blockquote><p>Thanks for reviewing the drafts :</p><ul><li><a href="https://www.linkedin.com/in/sheikhhanif/">Sheikh Hanif</a> and</li><li><a href="https://www.linkedin.com/in/tahmida-sumbula-6711081a0/">Tahmida Sumbula</a></li></ul><p><em>First appeared in </em><a href="https://omar.ai/posts/bitbucket_pipelines_custom_trigger/"><em>omar.ai</em></a><em>.</em></p><h4>References</h4><ul><li><a href="https://bitbucket.org/blog/an-introduction-to-bitbucket-pipelines">An introduction to Bitbucket Pipelines</a></li><li><a href="https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html">Configure bitbucket-pipelines.yml</a></li><li><a href="https://cloud.google.com/functions/docs/how-to">Cloud Functions : How-to guides</a></li><li><a href="https://www.primitivesense.com/case-studies/ci-with-testing-and-deploying-google-cloud-functions-within-bitbucket-pipelines/">Testing &amp; deploying Google Cloud Functions in BitBucket Pipelines</a></li><li><a href="https://confluence.atlassian.com/bitbucket/variables-in-pipelines-794502608.html">Varibles in pipelines</a></li></ul><h4>Definitions</h4><ul><li><a href="https://en.wikipedia.org/wiki/YAML">YAML</a> : YAML Ain’t Markup Language. It is commonly used for configuration files and in applications where data is being stored or transmitted. It uses both Python-style indentation to indicate nesting, and a more compact format that uses [] for lists and {} for maps[1] making YAML 1.2 a superset of JSON.</li><li><a href="https://en.wikipedia.org/wiki/Docker_(software)">Docker</a> : Is a form of delivering software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines. In this post, docker images have been used run all the commands in the yml file.</li><li><a href="https://en.wikipedia.org/wiki/DevOps">DevOps</a> : DevOps is a set of practices that combines software development and information-technology operations which aims to shorten the systems development life cycle and provide continuous delivery with high software quality.</li><li><a href="https://en.wikipedia.org/wiki/CI/CD">CI/CD</a> : Generally refers to the combined practices of continuous integration and either continuous delivery and/or continuous deployment. <a href="https://opensource.com/article/18/8/what-cicd">More detailed</a>.</li><li>Pipelines : The steps that needs to be done to perform CI/CD.</li><li><a href="https://en.wikipedia.org/wiki/Bitbucket">Bitbucket</a> : Bitbucket is a web-based version control repository hosting service owned by Atlassian, for source code and development projects that use either Mercurial or Git revision control systems. Bitbucket offers both commercial plans and free accounts.</li><li><a href="https://en.wikipedia.org/wiki/Google_Cloud_Platform">Google Cloud Platform (GCP)</a> : Google Cloud Platform, offered by Google, is a suite of cloud computing services that runs on the same infrastructure that Google uses internally for its end-user products, such as Google Search, Gmail and YouTube.</li><li><a href="https://cloud.google.com/functions">Cloud functions</a> : Cloud Functions is Google Cloud’s event-driven serverless compute platform. Run your code locally or in the cloud without having to provision servers. Go from code to deploy with continuous delivery and monitoring tools. Cloud Functions scales up or down, so you pay only for compute resources you use. Easily create end-to-end complex development scenarios by connecting with existing Google Cloud or third-party services.</li></ul><p><a href="#scenerio">Go up.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22a726428143" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>