When i have different values for $version_data and $latest_version my scripts is executing the code testing stage
stages:
- Code Testing
- Deploy
# - Build Baselines
Testing:
stage: Code Testing
rules:
- if: "$version_data == $latest_version"
when: always
- when: never
script:
- echo "test script is starting"
- echo $version_data
- echo $latest_version
deployment:
stage: Deploy
only:
refs:
- schedules
- master
variables:
- $SCHEDULE_TYPE == "Deployment"
tags:
- shell
script:
- cd..
Output of the script:
snim2
2
Hi @sreekanthtoronto
I wonder whether this has something to do with Bash quoting? What do you get if you change:
- if: “$version_data == $latest_version”
when: always
to:
- if: '$version_data == $latest_version'
when: always
?
1 Like
Hi Snim,
I made a mistike here, i was trying to use those 2 fields from Before script. I think we cant use those 2 varibles in rules from script variables.
before_script:
- $latest_version = git describe --tags
- $version_data = Get-Content “VERSION.txt”
#- $version_data = $latest_version
- echo $version_data
- echo $latest_version
Do we have any other way to extract those 2 variable and run the stage based on those 2 variables?
snim2
4
It’s hard for me to tell exactly what your .gitlab-ci.yml
file looks like from your description.
If I have a CI config like this:
stages:
- stage
workflow:
rules:
- if: $CI_MERGE_REQUEST_ID
when: never
- when: always
job:
stage: stage
before_script:
- GIT_VERSION=$(git --version)
script:
- echo ${GIT_VERSION}
Then the output looks like this:
$ GIT_VERSION=$(git --version)
$ echo ${GIT_VERSION}
git version 2.20.1
Cleaning up project directory and file based variables
00:00
Job succeeded
Which makes me think that your problem is probably to do with the syntax of your Bash commands within your .gitlab-ci.yml
.