admin管理员组

文章数量:1278880

I have an QA automation suite running on pytest and selenium on CircleCI. I need the suite with run the following command when the branch name contains the word "_CRITICAL"

pytest $TEST_FILES --html=reports/index.html --junitxml=reports/junit.xml -m critical

my branch name is

ENROLL-7697-critical-path-qa-atuomation-for-enroll_CRITICAL

Somehow the variable "IS_CRITICAL" is not being assigned any value when It must be 1 since the branch name contains the string "_CRITICAL"

This is my code in my .yml file

Does anyone have an idea of why the variable is not getting the value "1" ?

version: 2.1

orbs:
  slack: circleci/[email protected]

parameters:
  parallelism:
    type: integer
    default: 4

jobs:
  build:
    parallelism: << pipeline.parameters.parallelism >>
    working_directory: /opt/automation
    docker:
      - image: enggaccounts/pytest-base-ci:0.0.2
        auth:
          username: $DOCKERHUB_USER
          password: $DOCKERHUB_PASSWORD

    steps:

      - run:
          name: Figuring Enroll Data
          command: |
              if echo $CIRCLE_BRANCH | grep -q "_ENV_"; then
                params_str="${CIRCLE_BRANCH#*_ENV_}"
                env=${params_str/_*}
                =''
                year=''
                is_custom='0'
                critical=1

                if echo $CIRCLE_BRANCH | grep -q "_ORG_"; then
                  params_str="${CIRCLE_BRANCH#*_ORG_}"
                  ="${params_str/_*}"
                fi

                if echo $CIRCLE_BRANCH | grep -q "_YEAR_"; then
                  params_str="${CIRCLE_BRANCH#*_YEAR_}"
                  year="${params_str/_*}"
                fi

                if echo $CIRCLE_BRANCH | grep -q "_CUSTOM"; then
                  is_custom='1'
                  echo "export IS_CUSTOM=${is_custom}" >> "$BASH_ENV"
                  source "$BASH_ENV"
                fi

                if echo $CIRCLE_BRANCH | grep -q "_CRITICAL"; then
                  critical="1"
                  echo "export IS_CRITICAL=${critical}" >> "$BASH_ENV"
                  source "$BASH_ENV"
                fi

                if [ ${#env} -gt 0 ]; then
                  echo "$env"
                  echo "export ENROLL_ENVIRONMENT=${env}" >> "$BASH_ENV"
                else
                  echo "Custom branch pattern detected but ENV was not defined!"
                fi

                if [ ${#critical} -gt 1 ]; then
                  echo "export IS_CRITICAL=${#critical}" >> "$BASH_ENV"
                fi

                if [ ${#} -gt 0 ]; then
                  echo "$"
                  echo "export ENROLL_ORGANIZATION=${}" >> "$BASH_ENV"
                else
                  echo "Custom branch pattern detected but ORG was not defined!"
                fi

                if [ ${#year} -gt 0 ]; then
                  echo "$year"
                  echo "export ENROLL_YEAR=${year}" >> "$BASH_ENV"
                else
                  echo "Custom branch pattern detected but YEAR was not defined!"
                fi

              else
                echo "$env"
                echo 'export ENROLL_ENVIRONMENT="dev"' >> "$BASH_ENV"
              fi

      - run:
          name: Debug BASH_ENV
          command: |
            echo "Contents of BASH_ENV:"
            cat "$BASH_ENV"

      - run:
          name: Debug Branch Name
          command: |
            echo "Branch name is: $CIRCLE_BRANCH"
            if echo $CIRCLE_BRANCH | grep -q "_CRITICAL"; then
              echo "CRITICAL branch detected"
            else
              echo "Not a CRITICAL branch"
            fi

      - run:
          name: Debug IS_CRITICAL
          command: |
            echo "IS_CRITICAL is set to: ${critical} or ${IS_CRITICAL}"

      - run:
          name: Install SSH
          command: |
            sudo apt-get update
            sudo apt-get -y install ssh git
      - add_ssh_keys
      - run:
          name: Add SSH Keys to Known Hosts
          command: |
            ssh-keyscan -p ${SSH_PORT} -H ${SSH_HOST} >> ~/.ssh/known_hosts
            ssh-keyscan -H github >> ~/.ssh/known_hosts
      - run:
          name: Create SSH Tunnel
          command: |
            ssh -4 -L ${SSH_TUNNEL} -Nf ${SSH_USER}@${SSH_HOST} -p${SSH_PORT}
            ssh-keyscan -p ${SSH_LOCAL_PORT} -H localhost >> ~/.ssh/known_hosts

      - run:
          name: Checkout Repo
          command: git clone -b ${CIRCLE_BRANCH} --single-branch --depth=1 ssh://git@localhost:${SSH_LOCAL_PORT}/schoolmint/schoolmint-pytest.git .

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v2-dependencies-{{ checksum "Pipfile.lock" }}
            # fallback to using the latest cache if no exact match is found
            - v2-dependencies-

      - run:
          name: Install pipenv
          command: sudo apt install -y pipenv

      - run:
          name: Install dependencies
          command: pipenv install

      - run:
          name: Setup the anization
          command: |
            if [ ${#ENROLL_ENVIRONMENT} -gt 0 ] && [ ${#ENROLL_ORGANIZATION} -gt 0 ] && [ ${#ENROLL_YEAR} -gt 0 ]; then
              echo "ENVIRONMENT: ${ENROLL_ENVIRONMENT}"
              echo "ORGANIZATION: ${ENROLL_ORGANIZATION}"
              echo "YEAR: ${ENROLL_YEAR}"
              pipenv run python3 setup.py -e ${ENROLL_ENVIRONMENT} -o ${ENROLL_ORGANIZATION} -y ${ENROLL_YEAR}
            elif [ ${#ENROLL_ENVIRONMENT} -gt 0 ]; then
              echo "ENVIRONMENT: ${ENROLL_ENVIRONMENT}"
              echo "ORGANIZATION: -"
              echo "YEAR: -"
              pipenv run python3 setup.py -e ${ENROLL_ENVIRONMENT}
            else
              echo "ENVIRONMENT: -"
              echo "ORGANIZATION: -"
              echo "YEAR: -"
              pipenv run python3 setup.py
            fi

      - run:
          name: Organization information
          command: |
            ORGANIZATION=$(grep 'ORGANIZATION=' .env | cut -d '=' -f2-)
            SCHOOL_YEAR=$(grep 'SCHOOL_YEAR=' .env | cut -d '=' -f2-)
            APP_BASE_URL=$(grep 'APP_BASE_URL=' .env | cut -d '=' -f2-)
            echo "Organization: $ORGANIZATION"
            echo "School Year: $SCHOOL_YEAR"
            echo "App base url: $APP_BASE_URL"

      - save_cache:
          key: v2-dependencies-{{ checksum "Pipfile.lock" }}
          paths:
            - "~/.cache/pipenv"

      - run:
          name: Debug IS_CRITICAL Before Running Tests
          command: |
            echo "IS_CRITICAL before running tests: $critical"

      - run:
          name: Run tests
          command: |
            set -e
            mkdir -p reports

            if [[ "$IS_CRITICAL" == 1 ]]; then
                echo "Running only CRITICAL tests"
                TEST_FILES=$(circleci tests glob "enroll/**/tests/*.py" | circleci tests split --split-by=timings)
                pipenv run pytest $TEST_FILES --html=reports/index.html --junitxml=reports/junit.xml -m critical
            elif [[ "$IS_CUSTOM" == 1 ]]; then
                echo "Running only CUSTOM tests"
                TEST_FILES=$(circleci tests glob "enroll/**/tests/*.py" | circleci tests split --split-by=timings)
                pipenv run pytest $TEST_FILES --html=reports/index.html --junitxml=reports/junit.xml -m custom
            else
                echo "Running ALL tests"
                TEST_FILES=$(circleci tests glob "enroll/**/tests/*.py" | circleci tests split --split-by=timings)
                pipenv run pytest $TEST_FILES --html=reports/index.html --junitxml=reports/junit.xml
            fi

      - store_test_results:
          path: reports

      # Save artifacts
      - store_artifacts:
          path: reports

      # Slack notifications
      - slack/notify:
          event: pass
          custom: |
            {
              "attachments": [
                {
                  "color": "#1cbf43",
                  "fallback": "A $CIRCLE_JOB job has succeeded!",
                  "text": "</$CIRCLE_USERNAME|$CIRCLE_USERNAME> A `$CIRCLE_JOB` job has succeeded!",
                  "fields": [
                    {
                      "title": "Project",
                      "value": "$CIRCLE_PROJECT_REPONAME",
                      "short": true
                    },
                    {
                      "title": "Branch",
                      "value": "$CIRCLE_BRANCH (<$CIRCLE_PULL_REQUEST|PR>)",
                      "short": true
                    }
                  ],
                  "actions": [
                    {
                      "type": "button",
                      "text": "Job $CIRCLE_BUILD_NUM",
                      "url": "$CIRCLE_BUILD_URL"
                    }
                  ]
                }
              ]
            }

      - slack/notify:
          event: fail
          custom: |
            {
              "attachments": [
                {
                  "color": "#ed5c5c",
                  "fallback": "A $CIRCLE_JOB job has failed. $CIRCLE_PR_USERNAME",
                  "text": "</$CIRCLE_USERNAME|$CIRCLE_USERNAME> A `$CIRCLE_JOB` job has failed!",
                  "fields": [
                    {
                      "title": "Project",
                      "value": "$CIRCLE_PROJECT_REPONAME",
                      "short": true
                    },
                    {
                      "title": "Branch",
                      "value": "$CIRCLE_BRANCH (<$CIRCLE_PULL_REQUEST|PR>)",
                      "short": true
                    }
                  ],
                  "actions": [
                    {
                      "type": "button",
                      "text": "Job $CIRCLE_BUILD_NUM",
                      "url": "$CIRCLE_BUILD_URL"
                    }
                  ]
                }
              ]
            }

workflows:
  build-workflow:
    jobs:
      - build:
          context: AWS

本文标签: yamlyml file is not detecting the branch name on CircleCIStack Overflow