title: How to set env variable from gitlab ci cd dynamically
body: <p>I would like to edit the <a href="https://i.stack.imgur.com/b4KLL.png" rel="nofollow noreferrer">gitlab cicd variables</a> thru my pipeline script.</p>
  <p>Flow:</p>
  <ol>
  <li>Submit merge request</li>
  <li>CI pipeline retrieve the version number (variable stored in the CICD project setting (refer to pic although the variable version is not included)</li>
  <li>version+1 and set back into the CICD project setting</li>
  <li>git tag the file based on version number</li>
  </ol>
  <p>the file i want to git tag is a bash script file and I am using Linuxx docker image. please advise</p>
  <p>current script</p>
  <pre><code>variables: 
    PROFILE_NAME: default
  
  default:
    image: docker-image
  
  stages: 
    - tagging
  
  Tag:
    stage: tag
    script:
      - yum install git -y
      - git --version 
      - git remote set-url --push origin ${CI_SERVER_PROTOCOL}://${GITLAB_PERSONAL_ACCESS_TOKEN_NAME}:${GITLAB_PERSONAL_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git
      - export &quot;VERSION=$(($VERSION +1 ))&quot; &gt; $INC_VERSION
      - echo 'after version:' $VERSION
      - echo 'after increment version:' $INC_VERSION
      - git push origin --tags
    only:
      refs:
        - merge_requests
      variables:
        - ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^dev/ || $CI_COMMIT_BRANCH =~ /^dev/ || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^release-/ || $CI_COMMIT_BRANCH =~ /^release-/)
    except:
      variables:
        - ($CI_COMMIT_BEFORE_SHA == '0000000000000000000000000000000000000000' &amp;&amp; $CI_MERGE_REQUEST_TARGET_BRANCH_NAME !~ /^./)
  </code></pre>