# Jenkins

Source: https://help.testapp.io/jenkins/

Build and upload both your Android (APK) & iOS (IPA) to notify your testers for testing and feedback using Jenkins Freestyle Project & Pipeline.

## Install Jenkins with Docker

Assuming Docker is installed, use the following command to start the Jenkins server.

```sh
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home --name jenkins jenkins/jenkins:lts-jdk17
```

Open `http://localhost:8080` and get the credentials from the log:

```sh
docker logs jenkins
```

Follow the instructions to complete the setup.

## Setup the Jenkins job

Depending on how you use Jenkins, please choose one of the two options to upload your package.

### Option 1: Freestyle Project

1. Create a `Freestyle Project` job. do not include spaces in the name, e.g. *upload-mobile-package*
2. Add parameters to the job as shown below

| Parameter Type | Parameter Name | Default Value | Description |
| --- | --- | --- | --- |
| String Parameter | api_token |  | You can get it from [https://portal.testapp.io/profile/tokens](https://portal.testapp.io/profile/tokens) |
| String Parameter | app_id |  | You can get it from your app page at [https://portal.testapp.io/apps](https://portal.testapp.io/apps) |
| Choice Parameter | release |  | It can be either both or android or ios |
| String Parameter | apk |  | /user/path/to/app.apk (if you select release both or android) |
| String Parameter | ipa |  | /user/path/to/app.ipa (if you select release both or ios) |
| String Parameter | release_notes |  | Manually add the release notes to be displayed for the testers |
| Boolean Parameter | notify |  | Send notifications to your team members about this release |

*Check* [*TA-CLI*](https://help.testapp.io/ta-cli/) *for more info*

3. Add an `Execute Shell` build step, and paste the following code

```bash
export INSTALL_DIR=`pwd`
if [ ! -f ${INSTALL_DIR}/ta-cli ]
then
  curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
else
  ${INSTALL_DIR}/ta-cli version | grep "You are using the latest version"
  if [ $? -ne 0 ]
  then
    curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
  fi
fi
export PATH=$INSTALL_DIR:$PATH
chmod 0755 $INSTALL_DIR/ta-cli

$INSTALL_DIR/ta-cli publish --api_token=$api_token --app_id=$app_id --release=$release --apk=$apk --ipa=$ipa --release_notes="$release_notes" --notify=$notify --source="Jenkins"
```

4. Integrate with existing Jenkins CI process

Call this job from other jobs which build the APK/IPA packages.

### Option 2: Pipeline (Jenkinsfile)

Add the below stage to your pipeline script after the build stage.

```groovy
node {
    stage('Upload to TestApp.io') {
        api_token = 'Your API Token'
        app_id = 'Your App ID'
        release = 'both'
        apk = '/tmp/data/sample-app.apk'  // /user/path/to/app.apk (if you select release both or android)
        ipa = '/tmp/data/sample-app.ipa' // /user/path/to/app.ipa (if you select release both or ios)
        release_notes = "My release notes..."
        notify = false

        // Install ta-cli
        sh '''
            export INSTALL_DIR=`pwd`
            if [ ! -f ${INSTALL_DIR}/ta-cli ]
            then
              curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
            else
              ${INSTALL_DIR}/ta-cli version | grep "You are using the latest version"
              if [ $? -ne 0 ]
              then
                curl -Ls https://github.com/testappio/cli/releases/latest/download/install | bash
              fi
            fi
        '''
        // Upload to TestApp.io
        sh "./ta-cli publish --api_token=$api_token --app_id=$app_id --release=$release --apk=$apk --ipa=$ipa --release_notes=$release_notes --notify=$notify --source=Jenkins"

    }
}
```

> **Tip:** Once your CI/CD pipeline uploads a build, team members using the [TestApp.io mobile app](https://help.testapp.io/mobile-app-getting-started/) receive a push notification and can install the build with a single tap. You can also create [share links](https://help.testapp.io/how-to-share/) to distribute builds to external testers and clients.

---

Need help? [Contact us](https://testapp.io/contact-us/). we're happy to assist!
