> For the complete documentation index, see [llms.txt](https://cedrus.gitbook.io/codesoju/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cedrus.gitbook.io/codesoju/bluemix-deployment.md).

# Bluemix Deployment

## Link Existing GitHub Repo with Bluemix and Set up Continuous Integration

It is a fair assumption that a lot of developers would be interested Bluemix platform functionalities blended in with something that they already developed. This chapter would help developers to integrate a project hosted on the GitHub with the Bluemix platform and to set up a continuous integration cycle with every commit and push to the GitHub. After following the steps below you would be able to link your GitHub repository with your Bluemix account, make changes to your projects in your favorite text editor, push those changes to the GitHub and watch from the Bluemix dashboard how it is picked up automatically and a build/deploy processes are triggered. After the deployment is finished you would be able to access your application in the cloud.

### Set up a GitHub repository

1. Create a **New Repo** on GitHub. Click Create a **new Repository**
2. Optional: add README and .gitignore
3. Copy the gitHub url for this repo
4. On your local machine go into the project folder
5. Initialize git with: **git init**
6. Type: **git add .**&#x20;
7. Type: **git commit -m “First commit”**&#x20;
8. Type: **git remote add origin** `<your_repo_url>`&#x20;
9. Type: **git push**&#x20;
10. Now the project is on the github and ready to be linked to the Bluemix

### Link this repository to your Bluemix account

1. On **Github** from this newly created project go to **Settings**
2. On the left sidenav there will be **Integrations\&Services**. Click it&#x20;
3. Click ‘**Add Service**’  and search for **IBM Bluemix DevOps Services**
4. In the prompt form **enter Bluemix credentials** and click **Add**
5. On the **Bluemix** go to  [DevOps Services](https://hub.jazz.net/) and click **Create a Project**
6. Click **Link To An Existing Repository**
7. Log in to GitHub if prompted
8. Select a repository from the dropdown

### Set up Continuous Integration

1. In the top Right Corner of your project inside [DevOpsServices](https://hub.jazz.net/) click on **Build\&Deploy** button
2. Click **Add Stage**
3. Click **Jobs**
4. Click **Add Jobs** and select from the dropdown

If Build\&Deploy picked and the checkbox for auto pick up was selected now the repo should be connected to the bluemix and every time the commit is made and pushed to GitHub it will be pushed into the bluemix as well and build\&deploy actions will be triggered automatically.

## Configure multiple environment credentials access with VCAP\_SERVICES

Bluemix services require a user to use credentials assigned to him/her by the Bluemix. The hard coded version is needed to run your application locally. But the hard coded version is not a good idea if the app is to be hosted in different places including GitHub. The Bluemix offers you to set up the configuration to use environmental variables they host. VCAP\_SERVICES help us to leverage this functionality to manage Bluemix services credentials on the appication side.

It can be done on the server side in the file corresponding to the environmental configuration parameters.

![](https://4003200735-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LJEac1z_W4FEYD64X-0%2F-LJEagJzqvIYySJlvQaF%2F-LJEas-H-dlohNa3kMwS%2FScreen%20Shot%202016-09-29%20at%2011.24.29%20AM.png?generation=1533565176268236\&alt=media)

Please follow the example of configuring the document\_conversion services:

```javascript
var document_conversion = {}; 
if (process.env.VCAP_SERVICES) {
    var services = JSON.parse(process.env.VCAP_SERVICES), 
        svcName;
    for (svcName in services) { 
        if (svcName.match(/^document_conversion/)) {
            document_conversion = services[svcName][0]['credentials']; 
        }
    }
}

// NOTE: the parameters after the || are for running the app locally
module.exports = {
    PORT: process.env.VCAP_APP_PORT || '<yourPortNumber>',
    BLUEMIX_SERVICE_CREDENTIALS: {
        'document_conversion': {
            'username': document_conversion.username || '<your username>',
            'password': document_conversion.password || '<your password>'
        }
    }
};
```

The next step would be simply to require the service and the configuration in your Node file and pull data for the service you need:

```javascript
var DocumentConversionV1 = require('watson-developer-cloud/document-conversion/v1'),
    config = require('<path_to_config_folder>')

    documentConversion = new DocumentConversionV1({
        username: config.BLUEMIX_SERVICE_CREDENTIALS.document_conversion.username,
        password: config.BLUEMIX_SERVICE_CREDENTIALS.document_conversion.password,
        version_date: '2015-12-01'
    });
```

This will allow you to configure multiple Bluemix services in the centralized manner and to access the credentials easily from any Node file.
