Search code examples
yamlshippable-ci

How to fix "length must be less than 40" error in shippable.yml file?


Shippable CI UI is showing me the following error:

ERROR: 1 validation error detected: Value '[if [ develop == master ]; then xxx-xx-prod; else xxx-xx-dev; fi]' at 'environmentNames' failed to satisfy constraint: Member must satisfy constraint: [Member must have length less than or equal to 40, Member must have length greater than or equal to 4]

This is my shippable.yml file:

branches:
  only:
    - develop
    - master
build:
  ci:
    - "echo 'CI is running'"
  post_ci:
    - "docker build -t=\"xxxx/xxx-xxxx:$BRANCH.$BUILD_NUMBER\" ."
    - "docker push xxxx/xxx-xxx:$BRANCH.$BUILD_NUMBER"
    - "pip install --upgrade botocore"
    - "pip install setuptools==34.0.1"
integrations:
  deploy:
    -
      application_name: seamless-ai
      env_name: if [ "$BRANCH" == "master" ]; then "xxx-xx-prod"; else "xxx-xx-dev"; fi
      image_name: xxxx/xxx-xxx
      image_tag: $BRANCH.$BUILD_NUMBER
      integrationName: AWS-int
      region: us-east-1
      type: aws
  hub:
    -
      integrationName: "Docker Hub"
      type: docker
language: node_js

So essentially, my issue is the following:

env_name: if [ "$BRANCH" == "master" ]; then "xxx-xx-prod"; else "xxx-xx-dev"; fi

Essentially what I need to do is:

If the branch is master, then env_name must be xxx-xx-prod otherwise, then env_name = xxx-xx-dev

How can I fix this issue?


Solution

  • Since we see that $BRANCH gets evaluated inside the value, a possible solution could be to write it to an env variable and then just replace that.

    This can be done by adding this line to post-ci:

        - if [ "$BRANCH" == "master" ]; then export ENV_NAME="xxx-xx-prod"; else export ENV_NAME="xxx-xx-dev"; fi
    

    and then in deploy:

        env_name: $ENV_NAME
    

    I have no idea whether that actually works.