<?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 Eleni Papanikolopoulou on Medium]]></title>
        <description><![CDATA[Stories by Eleni Papanikolopoulou on Medium]]></description>
        <link>https://medium.com/@elenipapanikolo?source=rss-54fbb1ca7320------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fKaiUz6WgqDFa1aB.jpg</url>
            <title>Stories by Eleni Papanikolopoulou on Medium</title>
            <link>https://medium.com/@elenipapanikolo?source=rss-54fbb1ca7320------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:02:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elenipapanikolo/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[Integrating CI/CD for MULTIPLE environments with Jenkins & Fastlane (Part 2/2)]]></title>
            <link>https://medium.com/@elenipapanikolo/integrating-ci-cd-for-multiple-environments-with-jenkins-fastlane-part-2-2-7f1df780bf7c?source=rss-54fbb1ca7320------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f1df780bf7c</guid>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[cicd-tools]]></category>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Eleni Papanikolopoulou]]></dc:creator>
            <pubDate>Sat, 19 Sep 2020 09:36:43 GMT</pubDate>
            <atom:updated>2020-09-24T21:55:33.174Z</atom:updated>
            <content:encoded><![CDATA[<h3>Configure Jenkins for different environments 🖇</h3><p>If we consider the goal that we defined in the <a href="https://medium.com/p/6e12b1ea5578/edit"><em>previous part</em>,</a> we have managed to create a Jenkins job in order to upload our application to Testflight for different feature branches. Therefore, what is left is the ability to do this for different environments for example a staging environment and a test production environment. Different environments are equivalent to different Xcode configurations (i.e different custom schemes) with specific build settings each. If we take a look to the three files above, MyScipt.groovy , Deploy.groovy and Fastfile, we will notice that there are some properties that are configuration specific which are:</p><ol><li>The app identifier</li><li>The configuration which corresponds to the different scheme created in Xcode</li><li>The provisioning profile name</li></ol><p>These properties are used in various places, mostly inside the Fastlane lanes. Consequently, in order to achieve our goal we should pass those properties as parameters in the lanes and use different values for each configuration. The syntax to have parameters in a lane is the following:</p><pre>lane :build do |options|</pre><p>and then a parameter can be obtained as follows:</p><pre>parameter = options[:parameter_name]</pre><p>So in our case, we need three different parameters as described above.</p><p>Now let’s say we have an environment called Staging and another one called TestProduction. We will need to implement two different jobs in Jenkins, identical to the job defined above, and connect it to two different scripts let’s say Stg.groovy and TestProduction.groovy. Those scripts will be identical apart from the following three different parameters:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ea2b9080ee247add08253a8334d24a3/href">https://medium.com/media/9ea2b9080ee247add08253a8334d24a3/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffe9398236ce66b84d1b012b4a158aa3/href">https://medium.com/media/ffe9398236ce66b84d1b012b4a158aa3/href</a></iframe><p>And the way we will use get those inside the build lane is:</p><pre>lane :build do |options|</pre><pre>bundle_id = options[:bundle_id]<br>configuration = options[:configuration]<br>provisioning_profile = options[:provisioning_profile]</pre><pre>.<br>.<br>.</pre><pre>end</pre><p>So the deploy function inside the Deploy.script will now get those parameters in the method signature:</p><pre>def deployWith(bundle_id, configuration, provisioning_profile) {</pre><pre>.<br>.<br>.</pre><pre>}</pre><p>Now the stages that use these parameters are the Run Tests stage, the Build stage and the Upload to Testflight stage, so these are the stages that need parameterization. The others (Checkout repo, Install dependencies, Reset simulators, and Cleanup at the end) will remain the same.</p><h4>Configure the Run Tests stage</h4><p>So we implement the Run tests stage by passing the configuration as a parameter in order to be used inside the corresponding lane as follows:</p><pre>stage(&#39;Run Tests&#39;) {<br>      sh &#39;bundle exec fastlane test configuration:$configuration&#39;<br>}</pre><p>Now the difficult part is to configure the test lane inside the Fastfile to use this parameter. The way to obtain the parameters is the following:</p><pre>lane :a_lane do |options|<br>         ....<br>bundle_id = options[:bundle_id]<br>configuration = options[:configuration]<br>provisioning_profile = options[:provisioning_profile]<br>         ...<br>end</pre><p>So the test lane, which needs to use only the configuration parameter, will now be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6e22197d0312275d46b31e7c742a18a/href">https://medium.com/media/e6e22197d0312275d46b31e7c742a18a/href</a></iframe><p>We can notice that in the scheme field we use the configuration parameter since the scheme is different for the different environments.</p><h4>Configure the Build stage</h4><p>The Build stage needs all three parameters. So we implement the Fastlane build command by passing those three parameters. The Build stage now inside the deployWith() function will be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/440f07a394f4090ef5e3b6c065a0be2e/href">https://medium.com/media/440f07a394f4090ef5e3b6c065a0be2e/href</a></iframe><p>This means that the build lane will be exactly the same as before apart from the commands that use those three parameters:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9cc3da79d1ee2ce668adf6cffa7b7a8/href">https://medium.com/media/d9cc3da79d1ee2ce668adf6cffa7b7a8/href</a></iframe><p>It’s easy to notice that wherever the bundle_id, configuration and provisioning_profiles values are used we use the parameter values instead of the hardcoded values.</p><h4>Configure the Upload To Testflight stage</h4><p>So we use the upload_to_testflight Fastlane command by passing the bundle_id as parameter. The Upload to TestFlight stage now inside the deployWith() function of the Deploy.groovy file will be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28c8217b55862928317d94b2686f2940/href">https://medium.com/media/28c8217b55862928317d94b2686f2940/href</a></iframe><p>Consequently the corresponding lane inside the Fastfile will now use the bundle_id as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecb01ed22bb27ec50a16b087eda111b3/href">https://medium.com/media/ecb01ed22bb27ec50a16b087eda111b3/href</a></iframe><p>And that’s it! We have managed to use the same Deploy.groovy and Fastfile for different configurations. But how are we going to separate those parameters for the different configurations?</p><p>In Jenkins, instead of having one job for all configurations, we can now create different jobs for each configuration which will be identical apart from the script they use. Therefore, as I mentioned earlier, we create a Stg job and we use the following Stg.groovy script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bcb121a195d6051dd4a5668a00ffdea/href">https://medium.com/media/7bcb121a195d6051dd4a5668a00ffdea/href</a></iframe><p>Same for the TestProduction configuration we create a new identical job and we use the following TestProduction.groovy script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41a00f2cc0a4543dc998dc4c7bf16699/href">https://medium.com/media/41a00f2cc0a4543dc998dc4c7bf16699/href</a></iframe><p>Notice that all of them use the same Deploy.groovy script and the same Fastfile which are the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d4776654e04ba958ed8e74f5cf6f399/href">https://medium.com/media/0d4776654e04ba958ed8e74f5cf6f399/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b765d6ba74845e49dcfb9be54f06922/href">https://medium.com/media/8b765d6ba74845e49dcfb9be54f06922/href</a></iframe><h3>End Goal Achieved 👏</h3><p>As I mentioned in a previous section, our end goal was to be able to upload to Testflight, automatically with the click of one button:</p><p>a) for multiple feature branches</p><p>b) for multiple configurations corresponding to a different environment</p><p>We have managed to achieve the afore mentioned, by having different jobs in Jenkins, which can be configured with a different branch. Each job corresponds to a different Xcode configuration and in extension, to a different environment, all of the them using the same 2 main files (Deploy.groovy and Fastlane) and different initial script files (Stg.groovy and TestProduction.groovy).</p><p>Of course, this can extend for multiple environments with the implementation of a simple initial script with only a few lines of code!</p><p>Thank you for bearing with me 😊 and I hope this proves helpful 🙏!</p><p>Special thanks to <a href="https://medium.com/u/d2295c5f4208">Pavlos-Petros Tournaris</a> and <a href="https://medium.com/u/f105ffab27c1">George Tsifrikas</a> for their precious feedback.</p><p>Twitter: <a href="https://twitter.com/elenipapanikolo">@elenipapanikolo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f1df780bf7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating CI/CD for MULTIPLE environments with Jenkins & Fastlane (Part 1/2)]]></title>
            <link>https://medium.com/@elenipapanikolo/integrating-ci-cd-for-multiple-environments-with-jenkins-fastlane-part-1-2-6e12b1ea5578?source=rss-54fbb1ca7320------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e12b1ea5578</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[fastlane]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Eleni Papanikolopoulou]]></dc:creator>
            <pubDate>Sat, 19 Sep 2020 09:33:03 GMT</pubDate>
            <atom:updated>2020-09-24T21:58:05.890Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*J-OIgdnPnND2MI40RTqVtA.jpeg" /></figure><p>Incorporating Continuous Integration (CI) and Continuous Delivery (CD) in the development process is undeniably the only way to validate the correctness of code changes and to identify integration errors from early on. It is also a way to have bug-free versions of an application, quickly available for testing, and ready to be shipped to production after significant code alterations.</p><p>By integrating CI/CD in our day-to-day work, the developers can achieve two significant goals: First, the ability to run test suites on a server which is different than the development machine, so as the engineer can continue working on developing new features in a distractions-free manner, and second, the ability to send remote builds to their Product Owner or QA Engineer, in order to demo/test/review a new feature even if they cannot build and run the project on their own machines.</p><p>But what happens when there are multiple staging environments, and tests must run in different servers or features must be tested in different environments? Here’s where the magic happens with Jenkins and Fastlane, tools that allow to automate the process for different configurations and this is exactly where this article focuses on.</p><p>There are many excellent articles and tutorials that describe in detail how to use Jenkins and Fastlane in order to set up CI for a mobile project. However, where I want to concentrate is how we can configure the relevant scripts to work for multiple environments.</p><h3>Jenkins &amp; Fastlane 🛠</h3><p>In order to understand how we can integrate CI in a project, we have to understand how <strong>Jenkins</strong> and <strong>Fastlane</strong> work. Very briefly, Jenkins is an open-source continuous integration server written in Java and it is one of the most widely used tools for managing continuous integration builds. Jenkins offers the ability to create delivery <strong>Pipelines </strong>which basically are<strong> </strong>lifecycle processes which are called <strong>Jobs</strong>, including build, document, test, package, stage, deploy, static analysis and much more. Jobs are interlinked with one another in a sequence forming the pipeline and this is where Fastlane gets involved.</p><p><strong>Fastlane</strong> is an open-source tool that is used to automate the deployment and distribution process of mobile projects (iOS &amp; Android) offering a great number of automation features within the lifecycle of a mobile app such as packaging, code signing, distribution of builds and many more. Fastlane allows to create <strong>Lanes </strong>which<strong> </strong>are basically scripts, meaning a series of commands called <strong>Actions </strong>that describe the workflow we want to automate.</p><h3>Our Goal 🥅</h3><p>So what we basically want to achieve is automate the process of distributing our iOS application by automating the uploading of our application to <strong>Testflight</strong>, from where the stakeholders (Product Owner, QA Engineer, Sales person that wants to demo the app, you name it) can log in and download it effortlessly. What is more, we want to take it a step further and be able to upload to Testflight, automatically with the click of one button:</p><p>a) for multiple feature branches</p><p>b) for multiple configurations corresponding to a different environment</p><p>This will be our end goal 🙏.</p><h3><strong>Prerequisites 🤓</strong></h3><p>In this article, we consider a prerequisite that Jenkins and Fastlane have been set up, there is a great number of tutorials out there that describe in detail how to successfully perform the set up. Additionally, Jenkins will need some plugins to be installed in order in order to allow Jenkins to be triggered from Github’s webhooks and run a job. Those are the <a href="https://plugins.jenkins.io/github/">Github plugin</a>, the <a href="https://plugins.jenkins.io/xcode-plugin/">Xcode plugin</a>, the <a href="https://plugins.jenkins.io/workflow-scm-step/">SCM plugin</a> (Source Control Management) which will be used in order to checkout our project from Github and the <a href="https://plugins.jenkins.io/credentials-binding/">Credentials Plugin</a> in order to bound credentials to environment variables.</p><h3>Let’s start 🙌🏻</h3><p>To begin with, we need to create a new Pipeline in Jenkins. This pipeline will be described by a script we are going to create that performs exactly this: uploading our app to Testflight.</p><p>From the Jenkins Main Dashboard menu below, we select the first option =&gt; <em>New Item</em> (Pipeline) and we create the Jenkins Job named “Upload to Testflight”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*2vYG3SmZiY_k8csD-cfirA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*ZO5qNulK2SErV_R0nnnpvw.png" /></figure><p>To proceed we select the <em>Configure</em> option from the left menu and we go on by adding the configuration for the pipeline we just created. We start by adding a small description.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*fSi5UtFVX_sYEhTRElsF7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gxrPndRCvI5XC3X4GqLN3w.png" /></figure><p>From the <em>Definition</em> field below, in the Pipeline section, we choose the the “Pipeline Script from SCM” option. This option instructs Jenkins to obtain the Pipeline from Source Control Management (SCM), which will be our cloned Git repository.</p><p>We add a parameter which will be the branch we want to build and upload to Testflight each time and also we add the link of the github repository by providing also a parameter for the github login credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M9yI2y8j0Tcq_tQ6lB_K3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BwDhtg6aY9CBJkm3GZnyNQ.png" /></figure><p>Finally we define the script which will describe the whole pipeline process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B2ZwuWHD1u9kOniBw8-Jww.png" /></figure><p>We hit the Save button and voila! We have managed to create our Job in Jenkins. Now we are ready to start writing our script!</p><p>We will basically use the <a href="https://www.jenkins.io/doc/book/pipeline/syntax/">Scripted Pipeline </a>approach. Our script is going to have several phases called stages which describe what our pipeline wants to do. We ultimately want to upload to Testflight but before uploading to Testflight, we want to make sure that our unit tests pass successfully. So the different phases of the automation script should include the following stages:</p><ol><li>Checkout repo</li><li>Install dependencies</li><li>Reset simulators</li><li>Run tests</li><li>Build project</li><li>Upload to Testflight</li><li>Cleanup</li></ol><p>Once we have written our script we want to hit the <em>Build with Parameters</em> option from the menu of the Pipeline we just created and specify the branch we want to build:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q0vAU-HKs7uPBfic0jVFGg.png" /></figure><p>After we hit the <em>Build</em> button, and the Pipeline runs successfully we will see the following, in Jenkins Stage view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KpzyLezLs8C4l8xRiaQ4Kg.png" /></figure><p>which will mean that we have successfully uploaded our app to Testflight!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*BhXC3ULVU2LElHD_XYEp4g.png" /></figure><p>In case one of those stages fails, it automatically means that the whole Job will fail and we will see the corresponding stage with a red color. In this case we can go to the <em>Console Output</em> option of the Job’s menu, review the logs and locate the cause of failure, and of course re-run the job after we have fixed the issue.</p><h3>The script 📜</h3><p>So in our script, that we named MyScript.groovy, we define a function called deploy() and inside we are going to implement the afore-mentioned stages as follows:</p><ol><li>Checkout repo</li></ol><p>We checkout our repository by using the checkout command of the SCM plugin which will run the project checkout using the configuration options that we specified in the Jenkins Pipeline.</p><pre>stage(&#39;Checkout&#39;) <strong>{<br>     </strong>checkout scm<br><strong>}</strong></pre><p>2. Install dependencies</p><pre>stage(&#39;Install dependencies&#39;) <strong>{<br>       </strong>sh &#39;gem install bundler&#39;<br>       sh &#39;bundle update&#39;<br>       sh &#39;bundle exec pod repo update&#39;<br>       sh &#39;bundle exec pod install&#39;<br><strong>}</strong></pre><p>Our project uses CocoaPods as Dependency Manager, therefore we need to run pod install in order to download the project’s dependencies. In order to execute this command, and all other shell commands, we use Bundler, which is a tool to manage a Ruby application’s gem. By executing the first 2 commands, we manage to install the bundler and then the bundler downloads all the gems that are specified in the project’s Gemfile. This is the stage where we can specify the set of tools that our app might need, for example Fastlane that we will use right after, or if we want a linter or <a href="https://github.com/danger/danger">Danger</a>, this is the place to determine those ruby gems. Then we go on and we run pod repo update in order to always have the latest pod versions and finally we run pod update in order to download the project’s dependencies.</p><p>3. Reset simulators</p><pre>stage(&#39;Reset Simulators&#39;) <strong>{<br>    </strong>sh &#39;bundle exec fastlane snapshot reset_simulators --force&#39;<br><strong>}</strong></pre><p>This step is optional but essential if we want to run the unit tests in the next stage effectively, and without having to worry about a potential stale condition of a simulator which may result in the unit tests failing.</p><p>So this is the first time that Fastlane gets in the picture. As I mentioned earlier, Fastlane uses <strong>Lanes</strong> and Fastlane has already a great number of predefined lanes, or we can create our own custom lanes inside a file called Fastfile. Here we are using a predefined lane that does exactly what we want.</p><p>So this command will delete and re-create all iOS simulators, which one might say it’s kind of extreme but sometimes “Drastic times call for drastic measures” 😜.</p><p>4. Run tests</p><pre>stage(&#39;Run Tests&#39;) <strong>{<br>    </strong>sh &#39;bundle exec fastlane test&#39;<br><strong>}</strong></pre><p>In this stage we run the unit tests of our project. Now the test is a custom lane that we have implemented inside our <strong>Fastfile</strong> and has the following implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f83030a413fac483f76420951e5cb26d/href">https://medium.com/media/f83030a413fac483f76420951e5cb26d/href</a></iframe><p>Here we use two basic Fastlane actions, the <a href="https://docs.fastlane.tools/actions/scan/">scan</a> and the <a href="https://docs.fastlane.tools/actions/slather/">slather</a>.</p><p>Scan is used in order to actually run the unit tests and can be configured with several parameters such as the workspace, scheme, code_coverage and most importantly the devices where we can specify the simulator in which we want to run our unit tests.</p><p>Slather is used in order to gather code coverage while running unit tests, and also takes several arguments such us the output directory of the coverage report and also an array of documents to ignore while gathering the code coverage.</p><p>This is where the Fastlane magic ✨ happens. By only defining this lane with just two actions we manage to effortlessly run our unit tests inside Jenkins. Note that they should obviously all be successful, otherwise this stage and the entire job will fail.</p><p>5. Build</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e60b13ddea97da470260e363c080ab68/href">https://medium.com/media/e60b13ddea97da470260e363c080ab68/href</a></iframe><p>In this stage we use the <a href="http://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#withenv-set-environment-variables">withEnv</a> Jenkins Pipeline function in order to set the necessary environment variables as specified <a href="https://docs.fastlane.tools/best-practices/continuous-integration/#environment-variables-to-set">here</a> according to the Fastlane documentation. So we specify the FASTLANE_USER environment variable. Afterwards we set two more environment variables, the MATCH_PASSWORD and the FASTLANE_PASSWORD which cannot be obtained without credentials. Basically they are stored, encrypted for obvious reasons, inside Jenkins under the “Credential” menu option of Jenkins Dashboard, in the <em>secret_text </em>format, and they are obtained by providing the credentialsId.</p><p>Again, for the build phase, we have implemented a custom lane inside the Fastfile which will be the most complex lane that we will need to create as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/217312c300a362c9ff0b26a0458427b1/href">https://medium.com/media/217312c300a362c9ff0b26a0458427b1/href</a></iframe><p>Now let’s take this step by step.</p><p>We start by using the <a href="https://docs.fastlane.tools/actions/match/">match</a> Fastlane action. Match basically creates all required certificates &amp; provisioning profiles which are stored in a separate git repository, so it basically automates the code signing experience. This means that prior to running match, we should have created a different Github repository where we have stored our provisioning profiles. Alternatively, if we don’t want to use match for the code signing, we can use the <a href="https://docs.fastlane.tools/actions/sigh/">sigh</a> and <a href="https://docs.fastlane.tools/actions/cert/">cert</a> actions.</p><p>Now this is where the interesting part comes up. What we want to automate, is to increase the build number for the same release in order not to do this manually every time from Xcode build settings. We are all aware of the fact that, in order to upload multiple times a build to Testflight for the same release, it automatically fails if we don’t increase the build number, and each time we have to go to the project settings or .plist file, do this manually and then try to re-upload it. With the above code, we manage to automate this procedure by following the 3 steps below:</p><ol><li><a href="https://docs.fastlane.tools/actions/get_version_number/]">get_version_number</a> : Get the version of the project that is currently uploaded</li><li><a href="https://docs.fastlane.tools/actions/latest_testflight_build_number/">latest_testflight_build_number</a>: Get the current build number for the version we obtained in the previous step</li><li><a href="https://docs.fastlane.tools/actions/increment_build_number/">increment_build_number</a>: Increment the build number by specified times (here by one).</li></ol><p>This is also Fastlane magic ✨ to me!</p><p>Finally we continue by calling the <a href="https://docs.fastlane.tools/actions/gym/">gym</a> action which makes the actual build and packaging of the application. It gets configured with several arguments such as the configuration, scheme, and xcargs where we can specify the bundle_identifier, export_options etc.</p><p>6. Upload to Testflight</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7df4e69017352065e0fcf07a0df2da9/href">https://medium.com/media/b7df4e69017352065e0fcf07a0df2da9/href</a></iframe><p>Again here, we specify the environment variables necessary, same way we did in the previous step, and we implement another custom lane inside the Fastfile as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b275123f1d26092f1f954821a750c474/href">https://medium.com/media/b275123f1d26092f1f954821a750c474/href</a></iframe><p>We use the <a href="https://docs.fastlane.tools/actions/pilot/">pilot</a> Fastlane command which uploads the generated .ipa file from the previous step to Testflight. With this action we can also specify a changelog. We can also skip the submission of the binary, which means, the .ipa file will only be uploaded and not distributed to testers.</p><p>7. Cleanup</p><p>Last but not least, this is the step where we perform the Workspace cleanup by using the <a href="https://www.jenkins.io/doc/pipeline/steps/ws-cleanup/">cleanup</a> Jenkins plugin.</p><pre>stage(&#39;Cleanup&#39;) <strong>{<br>    </strong>cleanWs notFailBuild: true<br><strong>}</strong></pre><p>This means that we delete the Workspace when the build is done since it’s no longer needed.</p><p>So to sum up, this is is how the deploy() function looks inside a Deploy.script we have created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c13f261543e4b09bcb444e4023e4dda/href">https://medium.com/media/9c13f261543e4b09bcb444e4023e4dda/href</a></iframe><p>And this is how our Fastfile looks like now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ecfeba09af305866a8cd5ecf79210fec/href">https://medium.com/media/ecfeba09af305866a8cd5ecf79210fec/href</a></iframe><p>The deploy() function is called from the script that we have defined in the job, the MyScript.groovy, and is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6633a21a74eb434c99a50342655a75f7/href">https://medium.com/media/6633a21a74eb434c99a50342655a75f7/href</a></iframe><p>We load the Deploy.groovy script and we call the deploy() function that does all the work. Here we can notice that we also load a <a href="https://gist.github.com/elenipapanik/f01324272ac9b14dc4ae4d29c67ce0e1">utils.groovy</a> script which basically helps us set some environment variables before starting the Jenkins.job. The <a href="https://plugins.jenkins.io/ansicolor/">ansiColor</a> is another Jenkins Plugin that is used in order to colorize the output of the steps in a pipeline build. Finally, we can notice that we start the script inside a</p><pre>node(label: &#39;ios&#39;)</pre><p>In the <a href="https://www.jenkins.io/doc/book/pipeline/jenkinsfile/">Scripted Pipeline</a>, the above node is a crucial first step as it allocates an executor and workspace for the Pipeline.</p><p>And this is how we have managed to create a Jenkins Job that distributes different feature branches of our application by defining the feature branch as a parameter in Jenkins.</p><h3>Part 2</h3><p>In the <a href="https://medium.com/@elenipapanikolo/integrating-ci-cd-with-jenkins-fastlane-for-multiple-environments-part-2-2-7f1df780bf7c"><em>next part</em></a><em>,</em> we will examine how we can configure Jenkins in order to distribute our application for different environments and thus for different Xcode configurations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e12b1ea5578" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating to Codable from a third party parsing library]]></title>
            <link>https://medium.com/@elenipapanikolo/migrating-to-codable-from-a-third-party-parsing-library-fd85298ef5a2?source=rss-54fbb1ca7320------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd85298ef5a2</guid>
            <category><![CDATA[codable]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[argo]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Eleni Papanikolopoulou]]></dc:creator>
            <pubDate>Wed, 29 May 2019 15:01:19 GMT</pubDate>
            <atom:updated>2020-04-18T17:57:06.719Z</atom:updated>
            <content:encoded><![CDATA[<p>Nowadays, JSON is one of the most widely used format in order to exchange data between a browser and a server. JSON parsing has always been one of the most challenging endeavours in iOS development since <a href="https://developer.apple.com/documentation/foundation/jsonserialization">JSONSerialization</a>, an option offered by the Foundation framework, is pretty verbose and cumbersome to both write and read. <a href="https://developer.apple.com/documentation/foundation/nscoding">NSCoding</a> is another option that is used essentially for archiving and distribution purposes. Both solutions include writing redundant and boilerplate code, introducing a significant degree of cognitive overhead.</p><p>Therefore, there have been many third party libraries that facilitate and simplify the JSON serialization and de-serialization. One of those libraries is <a href="https://github.com/thoughtbot/Argo">Argo</a> which allows to parse JSON in a functional and type-safe way, and this is the framework we had been using so far at <a href="https://medium.com/u/e5ecc5b405f2">Workable</a>.</p><p>However, at WWDC 2017 and the arrival of Swift 4, Apple introduced the new <a href="https://developer.apple.com/documentation/swift/codable">Codable</a> protocol as the suggested solution for encoding and decoding. Codable is basically the combination of <a href="https://developer.apple.com/documentation/swift/encodable">Encodable</a> and <a href="https://developer.apple.com/documentation/swift/decodable">Decodable</a> protocols, it is easy to adopt and provides support for <em>class</em>, <em>struct</em> and <em>enum</em> as well.</p><p>In this article we will explore the process of migrating from Argo to Codable, the challenges we went through and how we managed to overcome them by providing some helper protocols in order to achieve a gradual and smoother migration. Note that we will focus primarily in the decoding part of models.</p><h3>The challenge 🤔</h3><p>When we first started thinking of the migration, we came to the horrifying 😱 realisation that we had so many models in our project that was impossible to simply remove Argo and write the decoding code with Codable from scratch. Additionally, the dependency graph between models was so complicated, that would require to implement the decoding of many models at once. This means it would take an extensive amount of work hours, or even better days, during which the project would not even compile and although we did have unit tests, that was simply not an option.</p><h3>The solution 🙌🏻</h3><p>Therefore, we came up with the idea to implement an intermediate step: Our models would be Argo Decodable but simultaneously would be able to be decoded with Codable as well. This means that an Argo decodable model would also be able to have nested models that would be decoded with Codable and the other way round. A decoded with Codable model would be able to have nested models that are Argo decodable. Hence, we would be able to gradually retire Argo and the project would compile every step of the way. Now, that was great in theory, but as Jan L.A. van de Snepscheut said: “In theory there is no difference between theory and practice. In practice there is”. So let’s see how we managed to implement this in practice.</p><h3>Argo Decoding</h3><p>Let’s see first how we would decode a simple User type using Argo.</p><p>We want to parse the following JSON file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/922296d061e48230acdd1c44fe2d7e99/href">https://medium.com/media/922296d061e48230acdd1c44fe2d7e99/href</a></iframe><p>So the User model looks like this and is decoded with Argo as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/46f8e5e61ed42e3651214738ba2d9845/href">https://medium.com/media/46f8e5e61ed42e3651214738ba2d9845/href</a></iframe><p><em>SocialProfile</em> and <em>EmployeeLevel</em> are also decoded with Argo for the above code to work.</p><h3>Use Swift.Decodable models inside Argo.Decodable models</h3><p>Now what we want to try is to make <em>Social Profile</em> decoded with Codable and use it inside <em>User</em>. So <em>Social Profile</em> is decoded with Codable as follows:</p><pre>struct SocialProfile: Swift.Decodable {</pre><pre>   let type: String<br>   let url: String<br>   let username: String?<br>   let name: String?</pre><pre>}</pre><p>and <em>EmployeeLevel </em>which is an enumeration as follows:</p><pre>extension EmployeeLevel: Swift.Decodable {}</pre><p>If the keys inside the JSON are the same as the properties of the <em>struct</em> or <em>enum</em> there is no need to implement the <strong><em>init(from decoder: Decoder) </em></strong>method and this is exactly the magic ✨ of the Codable protocol. Now let’s see how we can use the <em>SocialProfile</em> type inside the <em>User </em>type<em>. </em>For this purpose, we implemented a protocol to be conformed by models that are already Swift.Decodable, in order to be used inside Argo decodable types, which we named <em>SwiftToArgoDecodable</em> and is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb501d9b65c1b587f943820a99a90438/href">https://medium.com/media/bb501d9b65c1b587f943820a99a90438/href</a></iframe><p>So what we basically do inside the protocol extension, is providing our own custom implementation of the <strong><em>decode(</em>_ json<em>: JSON)</em> </strong>function of <em>Argo.Decodable</em> protocol by using the <em>JSONDecoder</em> of Codable and thus conforming to the <em>Argo.Decodable</em> protocol. In detail, what we actually do is using Argo’s JSON object, we convert it to<em> jsonData</em> and use it inside the JSONDecoder(). And voila! Now we can erase the decoding code of SocialProfile with Argo, and simply make it conform to <em>SwiftToArgoDecodable</em> protocol as follows:</p><pre>struct SocialProfile: Swift.Decodable, SwiftToArgoDecodable {</pre><pre>  let type: String<br>  let url: String<br>  let username: String?<br>  let name: String?</pre><pre>}</pre><p>Although <em>SocialProfile</em> is a Swift decodable model, it can now be used inside other Argo decodable models, such as <em>User</em> in our case. Quite simple right? Now let’s see how we can do the opposite.</p><h3>Use Argo.Decodable models inside Swift.Decodable models</h3><p>Now we want to use the <em>Use</em>r type that is Argo decodable inside another <em>UserList</em> type which is Swift decodable:</p><pre>struct UserList: Swift.Decodable {</pre><pre>  let id: Int<br>  let users: [User]</pre><pre>}</pre><p>For this purpose we implemented a new protocol to be conformed by models that are already Argo decodable (<em>User)</em>, in order to be used inside Swift decodable types (<em>UserList</em>), which we named <em>ArgoToSwiftDecodable</em> and is the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58fd5ae83458d5baa29b785a783bb70b/href">https://medium.com/media/58fd5ae83458d5baa29b785a783bb70b/href</a></iframe><p>Now the protocol declaration is exactly the same with the <em>SwiftToArgoDecodable,</em> which makes sense considering that in both cases the models should be both Argo and Swift decodable. However, what we do differently here, is that we implement the <strong><em>init(from decoder: Decoder) </em></strong>function of Codable with our own custom implementation.</p><p>Normally, inside this function we would use a <a href="https://developer.apple.com/documentation/swift/keyeddecodingcontainer"><em>KeyedDecodingContainer</em></a> where we would specify the <em>CodingKeys</em>. However, since here we don’t know the coding keys we want a more generic implementation. Therefore we use a <a href="https://developer.apple.com/documentation/swift/singlevalueencodingcontainer"><em>SingleValueEncodingContainer</em></a> which according to Apple’s specification is:</p><blockquote>A container that can support the storage and direct encoding of a single non-keyed value.</blockquote><p>And in this line of code:</p><pre>let payload = try container.decode(JSON.self)</pre><p>we decode the payload as a <em>JSON</em> which is an enumeration provided by Argo:</p><pre>// A type safe representation of JSON.<br>public enum JSON {</pre><pre>   case object([String: JSON])<br>   case array([JSON])<br>   case string(String)<br>   case number(NSNumber)<br>   case bool(Bool)<br>   case null</pre><pre>}</pre><p>However if we run the aforementioned code we will get the following error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TBc4Hi_PNA_Uh-vSSNGq0w.png" /></figure><p>This happens because the compiler cannot understand which decode function to use, since <em>Argo.JSON</em> is not <em>Swift.Decodable</em>. Therefore, we have to “help” the compiler a tiny bit by implementing the <strong><em>init(from decoder: Decoder) </em></strong>inside an<em> Argo.JSON </em>extension so as to make it conform to Swift.Decodable as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4027ac42840dc4e74bdf54225be9964/href">https://medium.com/media/d4027ac42840dc4e74bdf54225be9964/href</a></iframe><p>As you can notice, we specify for each possible type (boolean, NSNumber, array, dictionary etc.) how the decoding should be and we throw a decoding error in case a type that is not included in any of the types specified comes up.</p><p>For other third party libraries, we would probably have to create a custom type like <em>Argo.JSON</em> and make it conform to <em>Swift.Decodable</em> in a similar way.</p><p>One last step is to make the <em>User</em> type conform to the <em>ArgoToSwiftDecodable</em> protocol instead of <em>Argo.Decodable</em> that was before as follows and we are ready.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad3a197c22f025e6f72f817ceed95b4d/href">https://medium.com/media/ad3a197c22f025e6f72f817ceed95b4d/href</a></iframe><p>Now <em>UserList </em>type can be decoded with Codable even though it contains a model of type <em>User </em>which is Argo decodable (which in extension contains a model of <em>SocialProfile</em> type which is decoded with Codable).</p><h3>Conclusion</h3><p>By implementing those two protocols and making our models conform to them we have managed to interchangeably use models that are decoded with both Codable and Argo. Therefore, during our migration, we can start gradually decode our models with Codable, and the project will compile at all times. What is more, the above methodology can be used for any third party libraries that are used for JSON parsing 🎉. Just keep in mind that is doesn’t all have to happen at once and you can achieve a smoother migration by making your models able to be decoded with both ways.</p><p>Hope it proves helpful!🙏🏽</p><p>You can find the example project <a href="https://github.com/elenipapanik/ArgoToCodableExample">here</a>.</p><p>Special thanks to <a href="https://medium.com/u/f105ffab27c1">George Tsifrikas</a> and <a href="https://medium.com/u/16a020408304">Kostas Kremizas</a> for their contribution!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd85298ef5a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>