Creating Tekton pipelines for Mobile Foundation

improve this page | report issue

Mobile Foundation in Cloud Pak for Apps is bundled with Tekton pipelines for automating common DevOps tasks related to Mobile Foundation.

The steps to deploy Mobile Foundation on OpenShift Container Platform (OCP) are the same irrespective of how you have obtained the OCP entitlement.

Prerequisites

Following are the prerequisites before you begin the process of installing Mobile Foundation instance using the Mobile Foundation Operator.

Tekton pipelines

Following Tekton Pipelines are available with Mobile Foundation on Cloud Pak for Apps.

  1. Mobile App Configuration Pipeline (mobile-app-registration-pipeline)
  2. Mobile App Build Pipeline for Android (mobile-app-build-android-pipeline)
  3. Mobile App Build Pipeline for iOS (mobile-app-build-ios-pipeline)
  4. Mobile App Distribution Pipeline (application-center-deploy)
  5. Mobile App Test Pipeline for Android (mobile-app-test-android-pipeline)

Steps for running the pipelines

  • Download the PPA for Mobile Foundation.
  • Extract the IBM-MobileFoundation-Openshift-Pak-<version>.tar.gz file.
  • cd to the location of the extracted folder
  • Login to the Cloud Pak For Apps instance using the command below.
    oc login --token=<access_token> --server=<server_instance>
    

NOTE: Make sure that you deploy the pipelines to the default namespace/project. Pipelines might fail to run in other namespaces due to permission issues.

Mobile App Configuration Pipeline

Execute the following command.

oc apply -f pipeline/mobile-app-registration -n <projectname>

Following is the output produced.

pipelineresource.tekton.dev/mobile-app-registration-git-resource created
pipeline.tekton.dev/mobile-app-registration-pipeline created
task.tekton.dev/mobile-app-registration-task created

Mobile App Build Pipeline for Android

Execute the following command to deploy the pipeline

oc apply -f pipeline/mobile-app-build-android -n <projectname>

Following is the output produced.

pipelineresource.tekton.dev/mobile-app-build-android-git-sresource created
pipeline.tekton.dev/mobile-app-build-android-pipeline created
task.tekton.dev/mobile-app-build-android-task created

Mobile App Build Pipeline for iOS

Prerequisites

You need to have a Xcode server setup on a publicly accessible Mac machine. Check the section Xcode server setup for building iOS apps.

Execute the following command once you have addressed the prerequisite.

oc apply -f pipeline/mobile-app-build-ios -n <projectname>

Following is the output produced.

pipeline.tekton.dev/mobile-app-build-ios-pipeline created
task.tekton.dev/mobile-app-build-ios-task created
pipelineresource.tekton.dev/mobile-app-build-ios-git-resource created

Mobile App Distribution Pipeline

Execute the following command.

oc apply -f pipeline/mobile-app-publish -n <projectname>

Following is the output produced.

pipelineresource.tekton.dev/appcenter-git-resource created
pipeline.tekton.dev/application-center-deploy created
task.tekton.dev/application-center-upload created

Mobile App Test Pipeline for Android

Prerequisites

For running the android application test pipeline you need to have a BitBar account with API key, device ID, framework ID and project ID.

Execute the following command.

oc apply -f pipeline/mobile-app-test-android -n <projectname>

Following is the output produced.

pipelineresource.tekton.dev/mobile-app-test-android-git-resource created
pipeline.tekton.dev/mobile-app-test-android-pipeline created
task.tekton.dev/mobile-app-test-android-task created

Above commands creates the tasks, pipelines and resources. We can see the tasks, resources and pipelines in the Tekton dashboard

Tekton Dashboard tasks

Tekton Dashboard resources

Tekton Dashboard pipelines

Running the pipeline with appropriate resources from the Tekton dashboard

  1. Edit the resource file with proper git repository URL of the application.
     pipeline/mobile-app-registration/appregistrationgitresource.yaml
     pipeline/mobile-app-build-android/ buildandoridgitresource.yaml
     pipeline/mobile-app-build-ios/ buildiosgitresource.yaml
     pipeline/mobile-app-publish/mobileapppublishgitresource.yaml
     pipeline/mobile-app-test-android/testandroidappgitresource.yaml
    
  2. Run the command to update the resources of the Tekton pipeline mobile-app-registration.
      oc apply -f pipeline/mobile-app-registration/appregistrationgitresource.yaml -n <projectname>
    

    Following is the output produced.

      pipelineresource.tekton.dev/mobile-app-registration-git-resource configured
    
  3. Run the command to update the resources of the Tekton pipeline mobile-app-build-android.
      oc apply -f pipeline/mobile-app-build-andorid/buildandoridgitresource -n <projectname>
    

    Following is the output produced.

      pipelineresource.tekton.dev/mobile-app-build-android-git-resource configured
    
  4. Run the command to update the resources of the Tekton pipeline mobile-app-build-ios.
      oc apply -f pipleline/mobile-app-build-ios/buildiosgitresource -n <projectname>
    

    Following is the output produced.

      pipelineresource.tekton.dev/mobile-app-build-ios-git-resource configured
    
  5. Run the command to update the resources of the Tekton pipeline mobile-app-publish.
      oc apply -f pipeline/mobile-app-publish/mobileapppublishgitresource.yaml -n <projectname>
    

    Following is the output produced.

      pipelineresource.tekton.dev/appcenter-git-resource configured
    
  6. Run the command to update the resources of the Tekton pipeline mobile-app-test-android.
      oc apply -f pipeline/mobile-app-test-android/testandroidappgitresource.yaml -n <projectname>
    

    Following is the output produced.

      pipelineresource.tekton.dev/mobile-app-test-android-git-resource configured
    

Running the pipelines using PipelineRun

Open the Tekton dashboard and click the Pipelines section.

  1. Click the Pipeline to run. PipelineRun

  2. Click Create PipelineRun. PipelineRun

  3. Select the PipelineResources git-source created above.
  4. Provide the required parameters and service account as default.
  5. Click Create PipelineRun. PipelineRun
  6. To view the logs and status of the PipelineRun. Go to the Tekton dashboard and select the PipelineRuns. PipelineRun

Deploying tekton triggers for webhooks

NOTE: These steps are required only if you want to use Webhooks.

Configuring tekton triggers for Android build pipeline

Prerequisites

Before using the tekton triggers for android build a github-token needs to be added to the trigger binding yaml file. Go to pipeline/android-pipeline-trigger/mfpandroidtriggerbinding.yaml file and edit the place holder {githubToken} with a valid github-token.

Execute the following command.

oc apply -f pipeline/android-pipeline-trigger -n <projectname>

Following is the output produced.

eventlistener.tekton.dev/mfp-android-webhook-listener created
route.route.openshift.io/mfp-android-webhook-route created
triggerbinding.tekton.dev/mfp-android-trigger-binding created
rolebinding.rbac.authorization.k8s.io/mfp-android-trigger-binding created
serviceaccount/mfp-android-triggers-sa created
triggertemplate.tekton.dev/mfp-android-trigger-template created
role.rbac.authorization.k8s.io/mfp-trigger-role created

Configuring tekton triggers for iOS build pipeline

Prerequisites

Before using the tekton triggers for ios few fields needs to be added to the trigger binding yaml file. Go to pipeline/ios-pipeline-trigger/mfpiostriggerbinding.yaml file and edit the following parameters {githubToken} , {xcodeServerBotId} and xcodeServerHost with valid values.

Execute the following command.

oc apply -f pipeline/ios-pipeline-trigger -n <projectname>

Following is the output produced.

eventlistener.tekton.dev/mfp-ios-webhook-listener created
route.route.openshift.io/mfp-ios-webhook-route created
triggerbinding.tekton.dev/mfp-ios-trigger-binding created
rolebinding.rbac.authorization.k8s.io/mfp-ios-trigger-binding created
serviceaccount/mfp-ios-triggers-sa created
triggertemplate.tekton.dev/mfp-ios-trigger-template created

Above commands creates the EventListeners,TriggerBindings and TriggerTemplates that can be accessed from the Tekton Dashboard.

Triggers

Triggers

Triggers

They also expose two routes that can be used to configure webhooks. From the openshift dashboard navigate to Networking and Routes , one is for android build and the other is for iOS build.

Triggers

Triggering pipelines using webhook

Run the pipeline with webhook to automatically trigger the PipelineRun whenever there are changes in the application git repository.

Creation of Webhooks

  1. Go to the Git repository for which you want to configure the webhook.
  2. Navigate to the Settings tab of the respository. Webhooks
  3. Click and Webhooks on the left navbar and then click on Add webhook.
  4. Provide the Payload URL field with one the routes that was created previously when tekton triggers are configured. The Content type should be set to application/json and select the event when you want the webhook to run. Webhooks
  5. Click Add Webhook

The event to the git repository shall trigger creation of a PipelineRun configured for that route. To view the logs and status of the PipelineRun. Go to the Tekton dashboard and select the PipelineRuns.

XCode Server setup for building iOS apps

  1. On a Mac machine, setup Xcode.
  2. Open Xcode.
  3. From the top menu select Xcode Server.
  4. Turn on the Xcode Server to run integrations.
  5. After the server is turned on go to Permissions section and change Create and View Bots option to all users.
  6. Go to Accounts section and add a new account with the account type Xcode Server and then choose the server that is available.
  7. After the Xcode Server is setup, the bot needs to be configured in order to run integrations and generate an ipa. Open the iOS project that you want to build in Xcode.
  8. Go to the build log for the project and select By Group option. The configured server should be visible.
  9. Right click the server and then click Create Bot.
  10. Give a name for the bot and click Next. Please make sure that the bot name does not contain any spaces. Configure the source control for the bot and click Next.
  11. In the build configuration under the Actions section, make sure Archive option is selected. Under the Export option select Use Custom Export Options Plist. Make sure you have a plist file in the following format. XCode
  12. In the Schedule bot integrations section, select the integrations to run Manually and then click Next. XCode
  13. Select the relevant build options for your project and click Next.
  14. In the Certificates and Profiles sections make sure relevant certificates and profiles required for the generating the ipa are added to the server and click Next.
  15. Add these arguments and provide relevant values for the xcodebuild command in the Arguments and Environment Variables section and click Next. XCode
  16. In the Triggers section click Add and select Pre-Integration script, give it a name and add the following script in the script section that downloads the CocoaPod dependencies for the app (if any) and then click Create.
    #!/bin/sh
    cd $XCS_PRIMARY_REPO_DIR
    PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands"
    . ~/.bash_profile
    bundle install
    npm install
    ionic cordova platform add ios
    ionic cordova prepare ios
    

    XCode

  17. After the bot is successfully created wait for the integration to run. After the integration is successful, go to the integration and go to Logs. In the logs you should be able to see the botId. The botId is needed for running the integrations from the Tekton pipelines. XCode
  18. Now the Xcode Server setup is successful. Use the bot ID to trigger the iOS build pipeline.
Inclusive terminology note: The Mobile First Platform team is making changes to support the IBM® initiative to replace racially biased and other discriminatory language in our code and content with more inclusive language. While IBM values the use of inclusive language, terms that are outside of IBM's direct influence are sometimes required for the sake of maintaining user understanding. As other industry leaders join IBM in embracing the use of inclusive language, IBM will continue to update the documentation to reflect those changes.
Last modified on July 02, 2020