Search code examples
command-line-interfaceibm-cloudcloud-foundryibm-cloud-tools

IBM Cloud: Multiple IBM Cloud CLI environments (sessions) from same local user


We are building an automation where we call IBM Cloud CLI command to do various IBM Cloud deployments and provisioning of services. The automation application is build as a container which has IBM Cloud CLI installed. While all the commands and respective API works well when ran individually and only once, multiple calls to the API get conflict at CLI level.

As I understand, this is because underneath the container, there is only one CLI session which can be created. This has defeated the purpose of automation and creating the rest APIs as I can ran my overall automation only in sequence. I wanted to know if there is any way where I can create different IBM Cloud CLI sessions for every call/API call.

When I searched, I do find that CF CLI do support multiple session by setting some env variable and giving session numbers. Wondering if such a thing possible with IBM Cloud CLI.


Solution

  • To be able to run multiple sessions in parallel, you would need to use different environments per session. When you issue ibmcloud -h you see this option:

    IBMCLOUD_HOME=path/to/dir Path to config directory

    Explicitly set up a different configuration directory for each of your sessions. I successfully tested that I can login under different IBM Cloud accounts from my same local (Linux) account at the same time.

    Env 1:

    export IBMCLOUD_HOME=/home/myuser/.ibmcloudenv1
    ibmcloud login
    

    Env 2:

    export IBMCLOUD_HOME=/home/myuser/.ibmcloudenv2
    ibmcloud login