How to specify a pipeline to run only when new feature branch is pushed?

Hello Everyone,

I am working on gitlab-salesforce integration pipeline. For now, I configured my gitlab-ci.yml file and it works fine for my master branch.

I am trying to put a condition - This pipeline should run only when new feature/test branch is pushed to repository.
I tried using rules but it gives me an error : * jobs only config should implement a script: or a trigger: keyword.

Below is my code and please suggest me the alternative.
rules :

stages :

  • deploy

variables:
SF_AUTOUPDATE_DISABLE : “true”

rules :

  • if: ‘$CI_COMMIT_REF_NAME = ~/^feature/*/’
  • when: always

deploy to Salesforce:
stage: deploy
script:

Install jq and node

  • apt update && apt -y install jq
  • apt-get update && apt-get install -y nodejs npm
  • node --version
  • npm --version
  • npm -y install node-gyp

Setup SFDX environment variables

Install Salesforce CLI

  • npm install --global sfdx-cli
  • sfdx --version
  • sfdx plugins --core

Install acu-pack

  • echo “y” | sfdx plugins:install @salesforce/acu-pack
  • sfdx acu-pack -h

Install Salesforce Code Analyzer

  • echo “y” | sfdx plugins:install @salesforce/sfdx-scanner
  • sfdx scanner -h

setup git user

  • git config user.name “GitLab Actions Bot”
  • git config user.email “<>”

Authenticate Org

  • echo “Authenticating Dev org”
  • echo “${JWT_KEY}” > server.key
  • sfdx force:auth:jwt:grant --jwtkeyfile server.key --clientid “${SALESFORCE_CONSUMER_KEY}” --username “${SF_USERNAME}” --instanceurl “${SALESFORCE_ORG_URL}”
  • echo “Authentication succeded”

Merge feature branch to target branch

  • git checkout $CI_COMMIT_REF_NAME
  • git fetch origin $CI_COMMIT_REF_NAME
  • git merge --no-ff origin/${CI_COMMIT_REF_NAME} -m “Merge ${CI_COMMIT_REF_NAME} into ${TARGET_BRANCH}” --allow-unrelated-histories

Generate delta package

  • git --no-pager diff HEAD^ --name-status --no-renames > git-diff.txt
  • sfdx acu-pack:source:delta:git -g git-diff.txt -s “${SOURCE_DIR}” -d deploy
  • echo “Listing components in deploy package…”
  • find deploy -type f

code scan

  • sfdx scanner:run --target deploy --category ‘Documentation’ --format csv --outfile code-scan-errors.csv

Deploy changes to org.

  • sfdx force:source:deploy -p deploy -u “${SF_USERNAME}” -g --verbose

Please use formatting or

code block

in order to see your configuration properly. This is very hard to read. I don’t know whats what.

Currently, your rules exist outside the scope of any jobs. I think this could be causing the error.

Try putting this under the deploy to Salesforce job:

rules:
  - if: ‘$CI_COMMIT_REF_NAME = ~/^feature/*/’
  - when: always