<?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 Wimukthi Indeewara on Medium]]></title>
        <description><![CDATA[Stories by Wimukthi Indeewara on Medium]]></description>
        <link>https://medium.com/@wimukthi?source=rss-e9b3c3152295------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Cm9OYUZ254pFS9mOI4zsOA.png</url>
            <title>Stories by Wimukthi Indeewara on Medium</title>
            <link>https://medium.com/@wimukthi?source=rss-e9b3c3152295------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:18:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wimukthi/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[Continuous Delivery for VMware AirWatch with Jenkins]]></title>
            <link>https://wimukthi.medium.com/continuous-delivery-for-vmware-airwatch-with-jenkins-6e253e17879f?source=rss-e9b3c3152295------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e253e17879f</guid>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[airwatch]]></category>
            <category><![CDATA[vmware]]></category>
            <category><![CDATA[continuous-delivery]]></category>
            <dc:creator><![CDATA[Wimukthi Indeewara]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 02:49:34 GMT</pubDate>
            <atom:updated>2022-07-26T02:49:34.501Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mORz5VP7Up5DG5yxeJbsFw.jpeg" /></figure><h3>Introduction</h3><ul><li><strong>What are Continuous Integration, Continuous Delivery, and Continuous Deployment?</strong><br>Before going into the topic, let&#39;s try to understand what CI and CD are. These are two acronyms frequently used in modern software development practices where CI stands for continuous integration, a fundamental DevOps best practice where developers frequently merge code changes into a central repository where automated builds and tests run. But CD can either mean continuous delivery or continuous deployment. Continuous Delivery is an extension of Continuous Integration since it enables automation to deploy all the code changes to an environment (dev, QA, stage, prod, etc.) after the changes have been merged. So after Continuous Integration, the developers can deploy their changes at any time by clicking a button. Continuous Deployment takes the process one step further than continuous delivery. Here, all changes that pass the verification steps at each stage in the pipeline are released to production, and it is fully automated. Only a failed verification step will prevent pushing the changes to production. In this article, I have discussed the continuous delivery of an application using a Jenkins job that will be deployed into a set of devices with the help of VMware AirWatch.</li><li><strong>What is VMware AirWatch?<br></strong>VMware AirWatch is an enterprise mobility software provider based in Atlanta which provides technologies that help IT administrators deploy, secure, and manage mobile devices, applications, and data, as well as Windows 10 and Apple Mac computers. For IT Admins, the world has never been more complex as they have so many different types of devices, applications, and end-users. The most common question is how do you enable secure access to company resources while also making it simple for the end-user. That’s where the workspace one comes in.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XRNMZ6xsbxkiMzRn9omMKA.jpeg" /></figure><p>In simple terms, <a href="https://www.techtarget.com/searchvirtualdesktop/definition/VMware-Workspace-ONE"><strong>VMware Workspace One</strong></a> is a digital workspace platform that makes it easy for the end-users to access the corporate resources that they need without sacrificing security.</p><h3>Overview</h3><ul><li><strong>Setting up Jenkins to fetch the artifacts from Github.</strong><br>Using Jenkins, the relevant application can be fetched from Github. In this example, I’m going to use an android application. First of all, you need to create a Github PAT(Personal Access Token), which will be discussed in the prerequisites section. Using the Github API, you can fetch the APK from Github Releases. Also, there are so many Python Libraries out there that can be used to fetch releases from Github.</li><li><strong>Setting up VMware Workspace ONE</strong><br>The next step is to set up the Workspace ONE UEM AirWatch console. One of Workspace ONE UEM&#39;s is the ability to manage different versions of the same application within the console. Because of this, we can upgrade as well downgrade the application to different versions depending on our needs. Probably setting up Workspace ONE would be a whole new article as there are multiple things we need to follow to set up the console. Mainly if you are from an organization or a company, there will be multiple environments where your console is up and running. (QA/Production). It is highly recommended that you need to test this workflow in a QA or a Test environment first before going into production.</li><li><strong>Understanding SmartGroups, Organizational Groups, and Products<br></strong>Most people have trouble understanding the purpose of these groups and what they are. So I will try to explain each of these in simple terms. To elaborate more on these, think of an organization that has different types of warehouses all over the world and uses various types of devices within these warehouses to manage their work. Suppose there are three types of devices ( Type_A, Type_B, Type_C) and multiple warehouses within a country (WH_1, WH_2, WH_3, and so on).</li><li><strong>Organizational Groups(OG):</strong> These groups do exactly as they sound, which helps to organize all the devices. Also, you can create sub-OGs inside the main OG. In the above scenario, we can use organizational groups to organize different devices within a single warehouse or multiple warehouses. <br><strong>ex:</strong> Type_A devices within a single warehouse, Type_B devices within multiple warehouses, etc<br>Navigate to <strong>Groups &amp; Settings &gt; Groups &gt; Organization Groups</strong> <strong>&gt; List View</strong> or through the organization group drop-down menu.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*MN-OdGRLA0NTgTvOWD4eQQ.png" /></figure><ul><li><strong>Smart Groups (SG):</strong> These are similar to assignment sheets. You can assign the devices as well as the applications to this assignment sheet. Specially you can assign multiple Organizational Groups to Smart Groups, which makes Smart Groups more powerful.<br>Navigate to <strong>Groups &amp; Settings &gt; Groups &gt; Assignment Groups</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bcx4lkLLSdy-u_C_LImyxA.jpeg" /><figcaption>figure 3 — Ways how OGs and applications can be assigned to SGs</figcaption></figure><p>As shown in the figure, multiple applications (if multiple versions of the same applications were assigned to an SG, only the latest version would be installed on all the devices assigned to that SG) and multiple OGs can be assigned to an SG in different ways. Accordingly, you can assign<br> — Multiple OGs to an SG<br> — Multiple OGs + Devices to an SG<br> — Only Devices to an SG</p><ul><li><strong>Products: </strong>Products are similar to a package that has ordered the installation of device profiles, applications, and files/actions to be either published to the relay server or pushed to devices based on the conditions you create. Products are the main feature of the Product Provisioning system in Workspace ONE UEM.<br>Navigate to <strong>Devices</strong> &gt; <strong>Provisioning</strong> &gt; <strong>Product List View</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*gxVab1GtFIGrxcO6JJlWmQ.png" /></figure><p>— Can add multiple Smart Groups to a Product<br> — Can add various actions to the Manifest area (ex: Install an application, Uninstall an application, install a profile, etc.)<br> — Can add conditions to install or download the application<br> — Can add another product as a dependency (this dependency product will execute before executing the main product)<br> — Can add multiple dependencies and adjust their order of execution</p><h3>Prerequisites</h3><ul><li><strong>Github-related credentials — </strong>Github Access Token<br><br>A personal access token(PAT) is an alternative to using passwords for authentication to GitHub when creating a release and uploading build artifacts using Github API. Follow the below procedure to configure a PAT.<br> — Verify the email associated with the Github account if it hasn’t been verified yet.<br> — Click <strong>Profile Photo → Settings → Developer settings →Personal access tokens →Generate new token</strong><br> — Give the token a descriptive name and an expiration date<br> — Select the scopes of permissions you’d like to grant to this token.<br>(I would suggest only giving the most needed permissions to get the job done)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*YZMrcn_mINsdMOlc.gif" /></figure><p>— Then, Generate the token and save it somewhere as it won’t show again after the popup is closed.<br> — To use your token to authenticate to an organization that uses SAML single sign-on, authorize the token. For more info: <a href="https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on">Authorizing a personal access token for use with SAML single sign-on</a></p><ul><li><strong>Jenkins Instance<br></strong>You need to have a Jenkins instance up and running in your local machine or hosted somewhere.</li><li><strong>AirWatch related credentials</strong><br>Below are the important credentials related to AirWatch.<br>If the AirWatch API is not enabled, enable API access in the AirWatch Console as below.<br><strong>Groups &amp; Settings</strong>&gt; <strong>All Settings</strong> &gt; <strong>System</strong> &gt; <strong>Advanced</strong> &gt; <strong>API</strong> &gt; <strong>REST API</strong>.<br><strong>Rest API URL</strong>: <a href="https://as1487.awmdm.com/API">https://host.awmdm.com/API</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4iuCaMjhF6-k4cMnIILleg.png" /></figure><p><strong>Two-Factor Authentication</strong> — Along with the standard headers, AirWatch REST API server authentication requires the following headers:</p><ul><li><strong>Authorization</strong> — Authorization header with base 64 encoding of API admin credentials. There are several authentication methods supported by VMware AirWatch. (Basic Authentication, Directory Authentication, Certificate Authentication)<br>The easiest way is to use basic authentication. To get the basic credential, you need to encode the admin credentials(the form should be “username: password”) using Base64. This can be easily done using python as follows. (replace the user and password with the appropriate credentials)</li></ul><pre>$ python -c &quot;import base64; print base64.b64encode(&#39;user:password&#39;)&quot;<br>dXNlcjpwYXNzd29yZA==</pre><ul><li><strong>aw-tenant-code</strong> — Header value same as API key randomly generated in the AirWatch Console.<br>As mentioned in the above figure, a newer API key can be made from the REST API section.</li></ul><p>Finally, the AirWatch API can be accessed as follows,</p><ul><li>Using CURL</li></ul><pre>curl -X &quot;GET&quot; &quot;https://host.awmdm.com/API/v1/help&quot; \ -H &quot;Authorization: Basic dXNlcjpwYXNzd29yZA==&quot; \ -H &quot;aw-tenant-code: bG9naW46cGFzc3dvcmFzZG/2FmYXNkZmFkc2Zhc2Zk=&quot;</pre><ul><li>Using Python</li></ul><pre>import requests<br>response = requests.get(<br>            url=&quot;https://host.awmdm.com/API/v1/help&quot;,<br>            headers={<br>                &quot;Authorization&quot;: &quot;Basic dXNlcjpwYXNzd29yZA==&quot;,<br>                &quot;aw-tenant-code&quot;: &quot;bG9naW46cGFzc3dvcmFzZG/2FmYXNkZmFkc2Zhc2Zk=&quot;,<br>            },<br>        )</pre><h3>Procedure</h3><p>In this first example, I’m going to install an android application on a group of devices. Here I’m fetching the APK from the Github Repository release.<br>Below is the summary of the entire process.</p><p><strong>1. Fetch the APK from Github to Jenkins using Github API</strong></p><p>Here first, we need to get the release details from Github. I’m using a python script to get the release from Github to Jenkins. Also, I’m going to execute the python script within the Jenkinsfile Stage.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/058b2fd4bff72e1ccc7d8596919aeb9e/href">https://medium.com/media/058b2fd4bff72e1ccc7d8596919aeb9e/href</a></iframe><p>So within the Jenkinsfile, we can execute this as a normal shell command. The environment variables must be set on the Jenksinfile. (In this case, <em>Personal_Access_Token and Release_Tag</em>). You can get them from the parameters from the Jenkins Job itself and set them as environment variables afterward.</p><pre>node {<br>   sh &#39;python get_release_apk.py&#39;<br>}</pre><p>2. <strong>Send the APK to VMware AirWatch using AirWatch REST API</strong><br>3. <strong>Install the APK as an Internal Application inside the AirWatch Console</strong><br>4. <strong>Assign the installed application to the smart group, which contains all the devices</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a269173365f9e6176cf4d0937d169685/href">https://medium.com/media/a269173365f9e6176cf4d0937d169685/href</a></iframe><p>This is a simple example of a Continous Delivery workflow of an android application from its release state in Github to the AirWatch Console internal application. Further, this can be extended to the following use cases with necessary adjustments.</p><ul><li>Advanced AirWatch Console Management with Products<br>With products, we have more flexibility over the application instead of assigning it to a smart group directly.</li><li>Application Downgrading<br>Normally application upgrades when we upload a newer version of the same application to the AirWatch Console. Specifically, the versionCode must be incremented up. But when downgrading, there is no direct option to downgrade the application. (Downgrading version is not supported in AirWatch) But this can be achieved using product provisioning by uninstalling the newer versions and resyncing the older versions.</li></ul><h3>Conclusion</h3><p>Overall, VMware AirWatch can be used for the following things,</p><ul><li><a href="https://www.techtarget.com/searchmobilecomputing/definition/mobile-device-management">Mobile device management (MDM</a>) — for configuring, securing, and enforcing policies on devices.</li><li><a href="https://www.techtarget.com/searchmobilecomputing/definition/mobile-application-management-MAM">Mobile application management (MAM</a>) — for deploying, securing, and enforcing policies on devices.</li></ul><p>These tasks can be automated using Jenkins as Continous Integration/Continous Delivery pipelines. This can be done using the AirWatch API, which provides endpoints for most of the things within the console. (But keep in mind to update the workflows since the API has many deprecated endpoints). Ultimately AirWatch Products can be used to do some advanced management activities.</p><p>Happy Coding! 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e253e17879f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Continuous Integration of Github Releases with Jenkins]]></title>
            <link>https://wimukthi.medium.com/continuous-integration-of-github-releases-with-jenkins-34788157077d?source=rss-e9b3c3152295------2</link>
            <guid isPermaLink="false">https://medium.com/p/34788157077d</guid>
            <category><![CDATA[releases]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[polling]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[continous-integration]]></category>
            <dc:creator><![CDATA[Wimukthi Indeewara]]></dc:creator>
            <pubDate>Sat, 26 Feb 2022 04:16:26 GMT</pubDate>
            <atom:updated>2022-03-20T14:24:35.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wx0-N304qjYp_pEY2t2c0w.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>Delivering the products or applications at high velocity is an important aspect of any company or organization. This is where <strong>DevOps</strong> comes into the traditional software development process. Specially DevOps is much more important in <strong>agile software development</strong> where many teams work on an iterative development process to deliver the product incrementally. In the same way, <strong>Continuous integration</strong> is a DevOps software development practice that often refers to the build or integration stage of a software release. Usually, the codebase needs to be built and run the relevant tests whenever the development teams merge new changes into their central repository. And at some point, if we want to deliver the project to the end-user, we can <a href="https://docs.github.com/en/repositories/releasing-projects-on-github/about-releases"><strong>create a release</strong></a> that bundles the code base and relevant artifacts. This manual process can be done more efficiently by integrating GitHub with <strong>Jenkins </strong>which is an open-source automation server. Today we will look into how we can set up a Continous Integration workflow that can automate the build, test, and creation of releases using the power of Jenkins.</p><h3>Overview</h3><p>Following is the overview of the procedure that we have to follow in order to automate the workflow. There are multiple ways to implement the pipeline which has been discussed later in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OpK9YKCOgHBXBfPME2NRlw.jpeg" /></figure><p><strong>Stage 1: </strong>When creating the tag locally, we can use an annotated tag instead of a lightweight tag if we want to add something to the release description.</p><ul><li>Lightweight Tag<strong>:</strong> <em>git tag v1.0.0</em></li><li>Annotated Tag<strong>:</strong> <em>git tag -a v1.0.0 -m “Github Release Description”</em></li><li>After that, push the tag into Github: <em>git origin push v1.0.0</em></li></ul><p><strong>Stage 2:</strong> Triggering the Jenkins job can be done in two ways. An appropriate method can be used according to the Jenkins development environment.</p><ul><li>Using <strong>GitHub WebHook</strong> (recommended)<br>If your Jenkins Server can be accessed from outside, then this is the best option you can use to trigger the Jenkins Job. A Github Webhook sends an HTTP POST payload to the Jenkins Server when something is pushed into the repository. Configuring the Github Webhook to successfully trigger a Jenkins job has been discussed later in this article.</li><li>Using <strong>SCM Polling<br></strong>In some cases, Jenkins Server will be hosted inside a private network (depending on the company or organization). In that case, the GitHub Webhook will not operate as the Jenkins server is behind a secure firewall. Most probably these firewalls are one way which means the Jenkins side can connect to anything outside its network, but things outside cannot send any requests to Jenkins. Because of that, Github Webhooks will not work if the Jenkins Server is behind a secure firewall.</li></ul><p>— One solution for this is to use <strong>SCM polling</strong>. Poll SCM periodically polls the <strong>SCM(Source Code Management) </strong>to detect any changes and if changes are found<em>(if new commits were pushed since the last build)</em>, it will build the project. We can adjust the polling time to suit our requirements. But the main drawback is that this method of polling doesn&#39;t get the changes in real-time. So it’s not much efficient compared to Github Webhooks.</p><p>— Another approach is to use a webhook forwarding service. <a href="https://smee.io/"><strong>Smee</strong></a><strong> </strong>is a webhook forwarding service that can be used in this case. Here, GitHub pushes an event (via HTTPS/JSON in this case) to Smee.io, and Jenkins in turn subscribes to Smee with an outgoing connection from a client. Jenkins only makes an outbound connection and this will work as long as the firewall is one way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sxjO97-IvNUpuWfAr9h-4g.jpeg" /></figure><p><strong>Stage 3:</strong> The project can be built and tested before creating a release in Github. Although the whole project is tested at the time of release creation, this step can be used optionally to mitigate any falsehoods that will happen before creating a release. A Jenkins pipeline job would be ideal for this workflow if the project is going to be tested again before assembling a release. A special file called <a href="https://www.jenkins.io/doc/book/pipeline/jenkinsfile/"><strong>Jenkinsfile</strong></a> which is written in <a href="http://groovy-lang.org/"><strong>Groovy</strong></a> will be used by the Jenkins Pipeline job to execute the workflow. All kinds of tests that the project should undergo before creating the release can be specified under separate stages in this Jenkinsfile.</p><p><strong>Stage 4/ Stage 5:</strong> Creating a new release from the latest tag and uploading built assets to Github using the <a href="https://docs.github.com/en/rest"><strong>GitHub REST API</strong></a><strong> </strong>can be done in several ways. If you are using a Jenkins Pipeline project this can be accomplished using a Shell Script or a Python script which will be defined under the post-action section of the Jenkinsfile. But both ways have their own ups and downs which will be discussed later in this article.</p><h3>Prerequisites</h3><ul><li><strong>Github Account</strong> — With a repository that can be built and tested. (I’m using an android project in this article to explain the workflow)</li><li><strong>Jenkins Server</strong> —In most cases, this could be public or sometimes it’s hosted behind a secure firewall.</li></ul><h3><strong>Procedure</strong></h3><h4><strong>Github Configuration</strong></h4><ul><li><strong><em>Setting up a Personal Access Token<br></em></strong>A personal access token(PAT) is an alternative to using passwords for authentication to GitHub when creating a release and uploading build artifacts using Github API. Follow the below procedure to configure a PAT.<br> — Verify the email associated with the Github account, if it hasn&#39;t been verified yet.<br> — Click <strong>Profile Photo → Settings → Developer settings →Personal access tokens →Generate new token</strong><br> — Give the token a descriptive name and an expiration date<br> — Select the scopes or permissions, you’d like to grant to this token. <br>(I would suggest only to give the most needed permissions to get the job done)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*MSjDB-WMTNksPMizR1krJQ.gif" /></figure><p>— Then Generate the token and save it somewhere as it won’t show again after the popup is closed. <br> — To use your token to authenticate to an organization that uses SAML single sign-on, authorize the token. For more info: <a href="https://docs.github.com/en/enterprise-cloud@latest/authentication/authenticating-with-saml-single-sign-on/authorizing-a-personal-access-token-for-use-with-saml-single-sign-on">Authorizing a personal access token for use with SAML single sign-on</a></p><ul><li><strong><em>Setting up a GitHub Webhook<br></em></strong>This method only works if the Jenkins Server can be accessed from outside. (If it’s under a secure firewall, use SCM Polling instead of WebHooks). Follow the below procedure to configure a Github Webhook.<br> — Go to the <strong>Github repository → Settings → Webhooks →Add webhook<br></strong> — <strong>Payload URL:</strong> Use the IP or domain name of your Jenkins host as the Jenkins_environment_URL<br> — <strong>Secret:</strong> Leave this field empty</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*KjaMih8BUBnkJIfz54wF7w.png" /></figure><blockquote><strong>Note</strong>: The Jenkins and <a href="https://plugins.jenkins.io/git/">Git Plugin</a> only triggers the jobs if you select “<strong>Just the push event</strong>” option. Although you can select the “<strong>Let me select individual events</strong>” option as an event type to trigger the webhook, that will not trigger the Jenkins Job when a new tag is pushed. So make sure to select the “Just the push event” option. Even though we only need to build the Jenkins job for new tag pushes only, the Webhook will trigger the Jenkins job for any kind of pushes to the repository. But later, Jenkins job itself can be configured to build only for new tag pushes.</blockquote><h4>Jenkins Configuration</h4><ul><li><strong><em>Setting up Jenkins<br></em></strong>Install the <a href="https://plugins.jenkins.io/github/"><strong>Github plugin</strong></a> if it’s not installed by following the below procedure.<br> — Go to <strong>Manage Jenkins →Manage Plugins →Available<br> </strong>— Then search for “Github plugin”, install the plugin and restart</li><li><strong><em>Setting up a Jenkins Job<br></em></strong>This part will be trickier if we are going to use SCM Polling to build the Jenkins job and also pipeline job as the project type. If we can use Webhooks, the configuration part for the Jenkins job will be pretty easy. Below are some important things we need to consider when following different approaches to configure the Jenkins Jobs. Also, the script to create a release and upload built artifacts to Jenkins will be discussed later in this article.</li></ul><h3><strong><em>Using Github Webhook to trigger Jenkins and Freestyle Project as the job type</em></strong></h3><ul><li><em>Configure the </em><strong><em>Github Webhook </em></strong><em>as mentioned above.</em></li><li><em>Under the </em><strong><em>“General</em></strong><em>” section select GitHub project and provide the Github Project URL</em></li><li><em>Under the “</em><strong><em>Source Code Management</em></strong><em>” section do the configuration as follows</em></li></ul><blockquote><strong>Repository URL:</strong> git@github.com:&lt;Organization&gt;/&lt;Repository&gt;.git<br> <strong>or</strong> https://github.com/&lt;Organization&gt;/&lt;Repository&gt;<br><strong>Credentials: </strong>Provide the credentials used to <strong>check out</strong> sources.</blockquote><p><em>In order to make sure that the Job is only building for new tags, do the following configurations further in the SCM section. ( click </em>“<strong>Advanced</strong>” in the SCM section<em>)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*NjzhihptvFux8kjNwueFNw.png" /></figure><p><strong>Refspec:</strong> +refs/tags/*:refs/remotes/origin/tags/*<br>A refspec controls the remote refs to be retrieved and how they map to local refs and if left blank, it will default to the normal behavior of git fetch, which retrieves all the branches. Here, we only need tags so we set the refspec to tags only.</p><p><strong>Branch Specifier:</strong> refs/tags/*<br><em>This specifier tells Jenkins to only build on new tags, no matter how the tag is named. So this t</em>racks/checks out the specified tag.</p><ul><li><em>Next, under the “</em><strong><em>Build Triggers”</em></strong><em> Select the </em><strong><em>“GitHub hook trigger for GITScm polling”</em></strong></li><li><em>Finally provide the script in the “</em><strong><em>Build</em></strong><em>” area of the Freestyle Project to build the application, create a release and send the built artifacts to Github using Github API. (This script is available in the final section of the article)</em></li></ul><h3><strong><em>Using Github Webhook to trigger Jenkins and Pipeline Project as the job type</em></strong></h3><ul><li><em>Configure the Github Webhook as mentioned above.</em></li><li><em>Do the same configuration to the “</em><strong><em>General”</em></strong><em> and “</em><strong><em>Source Code Management</em></strong><em>” sections as mentioned above</em></li><li><em>Under the “</em><strong><em>Build Triggers”</em></strong><em> Select the </em><strong><em>“GitHub hook trigger for GITScm polling”</em></strong></li><li><em>Then write the script in the Jenskinsfile (A Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline and is checked into source control). The building and testing of the project can be done inside separate </em><strong><em>stages</em></strong><em> of the Jenkinsfile. Finally, the release creation and uploading of the built artifact to Github can be done in the post-action area of the Jenkinsfiles using a shell script or a python script. Below is a sample of the Jenkinsfile which is written in Groovy.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*0tNBrTKbRLCa4cuMF9GftQ.png" /></figure><h3><strong><em>SCM Polling to build the Jenkins Job and using a Freestyle Project as the job type</em></strong></h3><ul><li>Do the configuration as in “<strong><em>Using Github Webhook to trigger Jenkins and Freestyle Project as the job type</em></strong>”</li><li><em>Additionally under the “</em><strong><em>Build Triggers”</em></strong><em> Select the </em><strong><em>“Poll SCM”<br></em></strong><em>This field follows the syntax of cron (with minor differences). <br>Specifically, each line consists of 5 fields separated by TAB or whitespace: </em>MINUTE HOUR DOM MONTH DOW<br><em>E. g. </em>H/15 * * * *<em>: poll every fifteen minutes <br>But here we will configure this job to poll once a minute.<br></em>* * * * *<em>: poll once a minute</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*9ZLl9m5PZRNs7d-V2saRAA.png" /></figure><h3><strong><em>SCM Polling to build the Jenkins Job and using Pipeline Project as the job type</em></strong></h3><ul><li><em>This part is somewhat trickier to implement. As there is no “</em><strong><em>Source Code Management</em></strong><em>” Section, </em><strong><em>“Poll SCM” </em></strong><em>option doesn’t work in a Pipeline project. Instead we can use a Freestyle Job to do the polling and finally execute the Pipeline project from its “</em><strong><em>Build after other projects are built</em></strong><em>” option under “</em><strong><em>Build Triggers</em></strong><em>”.</em></li><li><em>First, configure a freestyle project(Job 1) as in “</em><strong><em>Using Github Webhook to trigger Jenkins and Pipeline Project as the job type”. </em></strong><em>And in the “</em><strong><em>Build</em></strong><em>” section execute a normal shell command just to build the job.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*ptOrYVmU_ApolF5uXNKOUQ.png" /></figure><ul><li><em>Next, create a Pipeline job similar to “</em><strong><em>Using Github Webhook to trigger Jenkins and Pipeline Project as the job type”</em></strong></li><li><em>Under the “</em><strong><em>Build Triggers”</em></strong><em> of Pipeline job, select the “</em><strong><em>Build after other projects are built</em></strong><em>” option and provide </em><strong><em>Job 1 </em></strong><em>as the Project to watch. Also, select “</em><strong><em>Trigger only if build is stable</em></strong><em>”.</em></li><li><em>This will successfully trigger the pipeline job when a new tag is created through SCM Polling.</em></li></ul><h3>Build Script</h3><p>Following are different scripts that you can use to create a release and upload the built artifacts to Github using Github Rest API. You can specify this script directly in the Jenkins Job if you are using a Freestyle job. If you want more maintenance on the scripts for the developers, you can add the script to the Github Repository and run the below python script in the “<strong>Build</strong>” area to fetch the script and execute it. For better security, you can save the Github Credentials as <strong>Secret Text</strong> inside Jenkins Credentials Manager and specify the Credentials under the “<strong>Build Environment</strong>” of the job. Select the “<strong>Use secret text(s) or file(s)</strong>” and provide the necessary bindings that the script in the “<strong>Build</strong>” section needed. (In this case, provide the <strong>Github Personal Access</strong> Token and <strong>Branch</strong> of the Github repository where the actual script is located). Also, you can fetch these secrets using os.getenv(&#39;Name_of_the_secret&#39;)</p><pre>import requests<br>import base64<br>import json<br>import os</pre><pre><strong># Github Specifics</strong><br>GITHUB_ACCESS_TOKEN = os.getenv(&#39;Personal_Access_Token&#39;)BRANCH = os.getenv(&#39;BRANCH&#39;)PATH = <br><br>FILE_URL = &quot;<a href="https://api.github.com/repos/%7B%7D/%7B%7D/contents/%7B%7D?ref={">https://api.github.com/repos/&lt;Organization&gt;/Repository/contents/</a>&lt;Scrip_Path&gt;<a href="https://api.github.com/repos/%7B%7D/%7B%7D/contents/%7B%7D?ref={">?ref={</a>}&quot;.format(BRANCH)</pre><pre><strong># Function to fetch get the python script and read it</strong><br>def github_read_file(url):<br>    r = requests.get(url, headers={&#39;Authorization&#39;: &#39;token %s&#39; %GITHUB_ACCESS_TOKEN})<br>    data = r.json()<br>    file_content = data[&#39;content&#39;]<br>    file_content_encoding = data.get(&#39;encoding&#39;)<br>    if file_content_encoding == &#39;base64&#39;:<br>        file_content = base64.b64decode(file_content).decode()<br>    return file_content</pre><pre><strong># Execute the python script returning from the above funtion</strong><br>exec(github_read_file(FILE_URL))</pre><p>Otherwise if you are using a Pipeline job, specify the script under the post-build area of the Jenkinsfile. Also if you are using a python script, execute the python script under the “<strong>post</strong>” section of the Jenkinsfile as follows. (Make sure the python script is in the same directory as the Jenkinsfile. Otherwise provide the relative path to the script)</p><pre>post {<br>        success {<br>            sh &#39;python &lt;Script_Name&gt;.py&#39;<br>        }<br>    }</pre><blockquote><strong>Note:</strong> If you are using a shell script, aware that some of the shell commands are not working properly inside Jenkinsfile. There will be json parsing problems and also other kinds of problems that may occur when executing shell commands inside a Jenkinsfile. If you are going to use a pipeline job, execute a python script in the post-action area as it will mitigate most of the problems.</blockquote><p>— If you are using a shell script in the <strong>Build</strong> section</p><pre>echo &quot;Script starting...&quot;;</pre><pre><strong>//Github Personal Access Token      </strong>        <br>token=&quot;&lt;YOUR GITHUB ACCESS TOKEN&gt;&quot;;</pre><pre><strong>//Get the latest git tag   </strong>             <br>tag=$(git describe --tags);                </pre><pre><strong>//Get git message associate with the tag  </strong>             message=&quot;$(git for-each-ref refs/tags/$tag --format=&#39;%(contents)&#39;)&quot;;                </pre><pre><strong>//Get the name</strong><br>name=$(echo &quot;$message&quot; | head -n1);</pre><pre><strong>//Get the description        </strong>        <br>description=$(echo &quot;$message&quot; | tail -n +3)<br>description=$(echo &quot;$description&quot; | sed -z &#39;s/\n/\\n/g&#39;)      </pre><pre><strong>//Create the release from tag(put the github default branch as the target_commitish)      </strong>   <br>release=$(curl -X POST -H &quot;Authorization:token $tag&quot; --data &#39;{\&quot;tag_name\&quot;:\&quot;$tag\&quot;,\&quot;target_commitish\&quot;:\&quot;develop\&quot;,\&quot;body\&quot;:\&quot;$description\&quot;,\&quot;draft\&quot;:false}&#39; <a href="https://api.github.com/repos/SyscoCorporation/swms-mobile-kotlin/releases);">https://api.github.com/repos/&lt;Organization&gt;/&lt;Repository&gt;/releases);</a><br></pre><pre><strong>//Extract the id of the release from the creation response</strong><br>id=$(echo &quot;$release&quot; | sed -n -e &#39;s/&quot;id&quot;:\ \([0-9]\+\),/\1/p&#39; | head -n 1 | sed &#39;s/[[:blank:]]//g&#39;)</pre><pre><strong>//Get the built artifact from Jenkins  </strong>         <br>file = */app/build/outputs/apk/release-*.apk;</pre><pre><strong>//Upload the artifact to Github  </strong>              <br>curl -X POST -H &quot;Authorization:token $token&quot; -H &quot;Content-Type:application/octet-stream&quot; --data-binary @file https://uploads.github.com/repos/<a href="https://api.github.com/repos/SyscoCorporation/swms-mobile-kotlin/releases);">&lt;Organization&gt;/&lt;Repository&gt;</a>/$id/assets?name=release.apk</pre><p>— If you are using a python script in the <strong>Build</strong> section</p><pre>import subprocess<br>import requests<br>import json<br>from subprocess import Popen, PIPE<br>import glob, os<br><br>print(&quot;Python Script Starting..&quot;)</pre><pre><strong>#Github Personal Access Token </strong><br>token=&quot;&lt;YOUR GITHUB ACCESS TOKEN&gt;&quot;</pre><pre><strong>#Get the latest tag</strong><br>process = subprocess.Popen([&quot;git&quot;, &quot;describe&quot;, &quot;--tags&quot;], stdout=subprocess.PIPE)</pre><pre><strong>#Get the tag name</strong><br>tag_info = process.communicate()[0]<br>tag = tag_info.split(&#39;-&#39;)[0]</pre><pre><strong>#Creating the release </strong><br>endpoint =&quot;https://api.github.com/repos/<a href="https://api.github.com/repos/SyscoCorporation/swms-mobile-kotlin/releases);">&lt;Organization&gt;/&lt;Repository&gt;</a>&quot; data = {&quot;tag_name&quot;:tag,&quot;name&quot;:&quot;SWMS Mobile - Release - %s&quot; % tag}<br>release = requests.post(endpoint,headers={&#39;Authorization&#39;: &#39;token %s&#39; %token},data=json.dumps(data))<br>id = release.json().get(&#39;id&#39;)</pre><pre><strong>#Get the Jenkins directory location to get the built artifact</strong><br>directory = os.getcwd()</pre><pre><strong>#Find the artifat using a wildcard</strong><br>filespec=&quot;*/app/build/outputs/apk/release-*.apk&quot;<br>release_apk = glob.glob(os.path.join(directory, filespec))[0]</pre><pre><strong>#Read the file as binary data</strong><br>with open(release_apk, &#39;rb&#39;) as f:<br>    data = f.read()</pre><pre><strong>#Uploading the artifact to Github</strong><br>upload_asset = requests.post(&quot;https://uploads.github.com/repos/<a href="https://api.github.com/repos/SyscoCorporation/swms-mobile-kotlin/releases);">&lt;Organization&gt;/&lt;Repository&gt;</a>/releases/%s/assets?name=release-%s.apk&quot; %(id,tag),headers={&#39;Authorization&#39;: &#39;token %s&#39; %token, &quot;Content-Type&quot;:&quot;application/octet-stream&quot; },data=data)</pre><p><em>But in some cases, the script is not executing successfully when the artifact size is somewhat large (&gt;20mb+). In that case, you can either send the file in small chunks or use a python library to upload the artifact using the </em><a href="https://docs.github.com/en/rest"><strong><em>GitHub REST API</em></strong></a><em>. Below is a script that is written with the help of the </em><a href="https://github.com/PyGithub/PyGithub"><strong><em>PyGithub</em></strong></a><em> Python library. But before proceeding, you have to install PyGithub to the Jenkins Environment. Or else if you have installed “</em><strong><em>pip</em></strong><em>”, you can install the PyGithub library within the script as follows.</em></p><pre>import glob<br>import os<br>import pip<br>import site<br>import sys<br>import requests</pre><pre><strong># Install PyGithub package</strong><br>if not os.path.exists(site.USER_SITE):<br>    os.makedirs(site.USER_SITE)<br><br>sys.path.insert(0, site.USER_SITE)<br>pip.main([&quot;install&quot;, &quot;--user&quot;, &quot;PyGithub&quot;])<br><strong><br># Create release and upload assets</strong><br>from github import Github <br><br>print(&quot;Python Script for CI workflow&quot;)<br><br>g = Github(&lt;GITHUB_PERSONAL_ACCESS_TOKEN&gt;)<br>repo = g.get_organization(organization).get_repo(repo_name)<br><br><strong># Get all tags at page 0</strong><br>tags = repo.get_tags()<br><br><strong># Sort tags by date to get the latest tag</strong><br>tags = sorted(tags, key=lambda tag: tag.commit.commit.author.date, reverse=True)<br>latest_tag = tags[0].name<br><br><strong># Create a release from the latest tag</strong><br>release = repo.create_git_release(<br>    tag=latest_tag,<br>    name=&quot;Release&quot;,<br>    message=&quot;&quot;,<br>)<br><br><strong>#Get the Jenkins directory location to get the built artifact</strong><br>directory = os.getcwd()</pre><pre><strong>#Find the artifat using a wildcard</strong><br>filespec=&quot;*/app/build/outputs/apk/release-*.apk&quot;<br>release_apk = glob.glob(os.path.join(directory, filespec))[0]</pre><pre><strong># Upload the built artifact to the created release</strong><br>release.upload_asset(<br>    path=release_apk,<br>    content_type=&#39;application/vnd.android.package-archive&#39;,<br>    name=&#39;release-%s.apk&#39; %latest_tag<br>)</pre><blockquote><strong>Note</strong>: If you want to add some documentation URL to the Github Release, you can use an annotated tag instead of a lightweight tag and specify the Documentation URL along with the tag as follows<br>E.g.<strong> git tag v1.0.0 “https://documentation_url.com” <br></strong>You can get this annotated tag message and add it as a hyperlink to the release description.</blockquote><pre><strong># Get the reference of latest tag in order to get the tag sha of annotated tag itself. (Important)</strong><br>tag_ref_command = &#39;git show-ref &#39; + latest_tag<br>tag_ref_stream = os.popen(tag_ref_command)<br>tag_ref_output = tag_ref_stream.read()<br>tag_sha =  tag_ref_output.split()[0]</pre><pre><strong># Get details of the reference</strong><br>tag_response = requests.get(&quot;https://api.github.com/repos/&lt;organization&gt;/&lt;repo_name&gt;/git/tags/$tag_sha&quot;,headers={&#39;Authorization&#39;: &#39;token %s&#39; %GITHUB_ACCESS_TOKEN, &quot;Content-Type&quot;:&quot;application/octet-stream&quot; }) </pre><pre><strong># Get the tag message from the reference details</strong><br>document_url = tag_response.json()[&quot;message&quot;].strip()</pre><pre><strong># Make the hyperlink body</strong><br>message = &quot;Release Note : [Release - %s](%s)&quot; %(latest_tag, document_url)<br>    <br><strong># Create the release from the latest tag and add a hyperlink of the  Documentation URL as the release body</strong><br>release = repo.create_git_release(<br>    tag=latest_tag,<br>    name=&quot;SWMS Mobile - Release - %s&quot; % (latest_tag),<br>    message=message<br>)</pre><h3>Conclusion</h3><p>This article provides various ways that you can implement the Continous Integration workflow for release automation with Jenkins which I have researched and developed. I have mentioned some important points that you need to know when publishing releases on Github when a tag(annotated/lightweight) is pushed. Although this workflow is not that much hard to implement, it’s not possible to natively use the Jenkins Github plugin to implement this workflow. So, I hope this guide helped you to customize and create your own automated workflow for release creation.</p><p><strong><em>References</em></strong></p><p>[1]: <a href="https://medium.com/@systemglitch?source=post_page-----814904e20776-----------------------------------">SystemGlitch</a>. February 11 2019). Continuous integration with Jenkins and Github Release <a href="https://medium.com/@systemglitch/continuous-integration-with-jenkins-and-github-release-814904e20776">https://medium.com/@arinbasu/you-can-use-footnotes-thus-babus%C2%B9-6c485c4eff1e</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34788157077d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>