Sobes.tech
Junior

Which branch do you use to apply changes in the test environment development pipeline?

sobes.tech AI

Answer from AI

develop or a specialized feature/bugfix branch, which is then merged into develop.

Options:

  • develop: The main development branch where all new features and fixes are integrated. It is ideal for continuous integration and testing of the latest changes.
  • Feature/Bugfix branches: For large features or urgent fixes, separate branches can be used. After completion, they are merged into develop. Testing on the test environment can occur either after merging into develop or directly from the branch, depending on the process.

The choice of approach depends on the branching strategy adopted by the team (Gitflow, Trunk-Based Development, etc.) and the configuration of CI/CD pipelines. In most cases, the test environment automatically deploys changes from the develop branch on each commit.

Example CI/CD configuration (Jenkins Groovy Script):

// Pipeline triggered on commit to develop branch
pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        stage('Build') {
            steps {
                sh './build.sh' // Application build
            }
        }
        stage('Deploy to Dev Test') {
            when {
                branch 'develop' // Deploy only from develop
            }
            steps {
                sh './deploy_to_dev_test.sh' // Deploy to test environment
            }
        }
        stage('Run Automated Tests') {
            steps {
                // Run UI/API tests on test environment
                sh './run_automated_tests.sh'
            }
        }
    }
}

Example CI/CD configuration (GitLab CI/CD):

# gitlab-ci.yml
stages:
  - build
  - deploy
  - test

build:
  stage: build
  script:
    - ./build.sh # Application build

deploy_dev_test:
  stage: deploy
  only:
    - develop # Deploy only from develop
  script:
    - ./deploy_to_dev_test.sh # Deploy to test environment

run_automated_tests:
  stage: test
  script:
    - ./run_automated_tests.sh # Run UI/API tests
  needs: ["deploy_dev_test"] # Run after successful deployment

In case feature branches are used, the pipeline can be configured to deploy temporary environments for testing these branches:

Example GitLab CI/CD with dynamic environments:

# gitlab-ci.yml
stages:
  - build
  - deploy
  - test
  - cleanup

build:
  stage: build
  script:
    - ./build.sh

deploy_feature_env:
  stage: deploy
  except:
    - develop
    - main
  script:
    - ./deploy_dynamic_env.sh $CI_COMMIT_REF_SLUG # Deploy temporary environment
  environment:
    name: review/$CI_COMMIT_REF_SLUG # Dynamic environment name
    url: http://$CI_COMMIT_REF_SLUG.test.example.com # Environment URL
    on_stop: cleanup_feature_env

run_feature_tests:
  stage: test
  except:
    - develop
    - main
  script:
    - ./run_tests_on_dynamic_env.sh http://$CI_COMMIT_REF_SLUG.test.example.com

cleanup_feature_env:
  stage: cleanup
  variables:
    GIT_STRATEGY: none
  script:
    - ./cleanup_dynamic_env.sh $CI_COMMIT_REF_SLUG
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    action: stop

Thus, the develop branch is most often used for the test environment, ensuring continuous testing of the latest changes. Depending on the process, feature or bugfix branches may also be used for targeted testing.