<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adam Goldschmidt</title>
    <description>The latest articles on DEV Community by Adam Goldschmidt (@adamgold).</description>
    <link>https://dev.to/adamgold</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F140418%2F840f9268-1c08-4036-a4b5-aff6a83e976a.jpeg</url>
      <title>DEV Community: Adam Goldschmidt</title>
      <link>https://dev.to/adamgold</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adamgold"/>
    <language>en</language>
    <item>
      <title>How to setup AppCenter with GitLab Without Pushing Secret Files</title>
      <dc:creator>Adam Goldschmidt</dc:creator>
      <pubDate>Thu, 07 Mar 2019 18:43:38 +0000</pubDate>
      <link>https://dev.to/adamgold/how-to-setup-appcenter-with-gitlab-without-pushing-secret-files-4mk8</link>
      <guid>https://dev.to/adamgold/how-to-setup-appcenter-with-gitlab-without-pushing-secret-files-4mk8</guid>
      <description>&lt;p&gt;We can all agree that having a tool to automate app builds, distributions and even &lt;strong&gt;analytics&lt;/strong&gt; can be quite nice. Well, this is exactly what &lt;a href="https://appcenter.ms" rel="noopener noreferrer"&gt;AppCenter&lt;/a&gt; does. And more.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/621y3s994ksbnxZZip/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/621y3s994ksbnxZZip/giphy.gif" alt="I want that"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  However...
&lt;/h4&gt;

&lt;p&gt;For those of us who use GitLab as their main Git server, it can be quite frustrating setting up GitLab to work with AppCenter. We also don’t want to push our app secrets to our Git server, whether it’s our Firebase JSON or the AppCenter secrets.&lt;/p&gt;

&lt;h3&gt;
  
  
  BitBucket Mirroring
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FOdXekub.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FOdXekub.png" alt="Screen Shot 2019-03-07 at 18.04.30"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to make AppCenter work "with" GitLab, we first have to mirror our repository to BitBucket. So go ahead and create a repository in BitBucket, then go to your user's &lt;code&gt;Settings&lt;/code&gt; (&lt;strong&gt;not repo settings&lt;/strong&gt;, and we're still in BitBucket), create a new app password under &lt;code&gt;App passwords&lt;/code&gt; with all available permissions, and copy the password you are given for later. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FCGjWUMu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FCGjWUMu.png" alt="Screen Shot 2019-03-07 at 18.13.21"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then go to GitLab, &lt;code&gt;Settings&lt;/code&gt; -&amp;gt; &lt;code&gt;Repository&lt;/code&gt;, and under &lt;code&gt;Mirroring Repositories&lt;/code&gt;, enter your BitBucket clone URL, choose &lt;code&gt;Push&lt;/code&gt; under &lt;code&gt;Mirror Direction&lt;/code&gt;, &lt;code&gt;Password&lt;/code&gt; as auth method, and paste in the password you've been given in BitBucket. Click &lt;code&gt;Mirror Repository&lt;/code&gt; and you should see a new row in the table below. Click the refresh button on the right to start syncing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup AppCenter
&lt;/h3&gt;

&lt;p&gt;That was the easy part. We still need to configure our builds and hide some secrets 😎&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://appcenter.ms/" rel="noopener noreferrer"&gt;AppCenter&lt;/a&gt;, and create a user if you don't already have one. Create your apps (For me it was one for Android and one for iOS) and complete the steps to add App Center’s SDK. Now go to &lt;code&gt;Build&lt;/code&gt;, and select &lt;code&gt;BitBucket&lt;/code&gt; under &lt;code&gt;Select a Service&lt;/code&gt;. Select your newly created repo, and then you should see all of your branches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build Scripts
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FS5Jv17A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.imgur.com%2FS5Jv17A.png" alt="Screen Shot 2019-03-07 at 18.04.00"&gt;&lt;/a&gt;&lt;br&gt;
Now in order for AppCenter to build your application, it needs the app's AppCenter secret (which you are given in settings, shown above), and if you use Firebase like me, it also needs the &lt;code&gt;google-services.json&lt;/code&gt; file (for Android) and &lt;code&gt;GoogleService-Info.plist&lt;/code&gt; for iOS. So what we need to do is to inject them before the build…. Let's write some code!&lt;/p&gt;

&lt;p&gt;Our file will be called &lt;code&gt;appcenter-pre-build.sh&lt;/code&gt;(so AppCenter can recognise and run it before building):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Injecting secrets..."&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Updating Google JSON"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$GOOGLE_SERVICES_JSON&lt;/span&gt; | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;--decode&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APPCENTER_SOURCE_DIRECTORY&lt;/span&gt;&lt;span class="s2"&gt;/android/app/google-services.json"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Updating Google plist"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$GOOGLE_SERVICES_PLIST&lt;/span&gt; | &lt;span class="nb"&gt;base64&lt;/span&gt; &lt;span class="nt"&gt;--decode&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APPCENTER_SOURCE_DIRECTORY&lt;/span&gt;&lt;span class="s2"&gt;/ios/GoogleService-Info.plist"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Updating android secret"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$ANDROID_SECRET&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APPCENTER_SOURCE_DIRECTORY&lt;/span&gt;&lt;span class="s2"&gt;/android/app/src/main/assets/appcenter-config.json"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Updating iOS secret"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$IOS_SECRET&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APPCENTER_SOURCE_DIRECTORY&lt;/span&gt;&lt;span class="s2"&gt;/ios/Glitz/AppCenter-Config.plist"&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Finished injecting secrets."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code is for both platforms, you can edit it how you like.&lt;/p&gt;

&lt;p&gt;Now the last thing there is to do is to insert the environment variables!&lt;/p&gt;

&lt;h3&gt;
  
  
  Environment Variables
&lt;/h3&gt;

&lt;p&gt;As our code shows, we have 4 environment variables. Let's go to the build configuration again, expand &lt;code&gt;Environment Variables&lt;/code&gt;, and add our 4 variables:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GOOGLE_SERVICES_JSON&lt;/code&gt;, &lt;code&gt;GOOGLE_SERVICES_PLIST&lt;/code&gt;, &lt;code&gt;ANDROID_SECRET&lt;/code&gt;, &lt;code&gt;IOS_SECRET&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Make sure to base64 encode the JSON values before entering them!
&lt;/h4&gt;

&lt;p&gt;(You can use &lt;a href="https://www.base64encode.org/" rel="noopener noreferrer"&gt;this site&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Now your build should run, and it should show &lt;code&gt;Injecting secrets…&lt;/code&gt; somewhere in the middle :)&lt;br&gt;
&lt;a href="https://i.giphy.com/media/zcCGBRQshGdt6/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/zcCGBRQshGdt6/giphy.gif" alt="Easy"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>gitlab</category>
      <category>automation</category>
      <category>ios</category>
      <category>android</category>
    </item>
  </channel>
</rss>
