Updating project level variable in yaml file

Hi,

We have a project level variable (Commit_Id) that we would like to update in our yaml file if the pipeline job is successful. We’ve tried updating the variable in our after script ( export Commit_Id=$CI_COMMIT_SHA) in the below code snippet, but the variable is not getting updated . Is there a different syntax we should be using? Thank you.

Validate-Dev:
  image: node:latest

  tags:

    - gitlab-org
   
  stage: validate

  only:

    - /^Develop$/i

  except:
    variables:
      - $SANDBOX_DISABLED

  script:
    - authenticate SANDBOX $Test_env
    - echo y | sfdx plugins:install sfdx-git-delta
    - sfdx sgd:source:delta --to "HEAD" --from "${Commit_Id}" --output Delta
    - sfdx force:source:deploy -x Delta/package/package.xml -u SANDBOX -c

  after_script:

   - >
     if [ $CI_JOB_STATUS == 'success' ]; then
        export Commit_Id=$CI_COMMIT_SHA

     else
        echo 'Pipeline encountered an error'
      fi

Versions

Please select whether options apply, and add the version information.

I’m not sure if this is efficient or best practice, but we were able to update the variable using a curl put request.

  after_script:
   - echo jobStatus $CI_JOB_STATUS
   - echo commitIdAfterscriptCurrent ${Commit_Id}
   - echo commitIdSHA $CI_COMMIT_SHA 
   - >
     if [ $CI_JOB_STATUS == 'success' ]; then
        curl --request PUT --header "PRIVATE-TOKEN: ${pToken}" \
        "https://gitlab.com/api/v4/projects/{Project Id} /variables/Commit_Id"  --form "value=$CI_COMMIT_SHA"
  
     
  
     else
        echo 'Pipeline encountered an error'
      fi