How to split the variable in Gitlab pipline (.gitlab-ci.yml) - gitlab

I have a branch name, for example, release-1.1.3, how I can split and extract the version by writing some logic in gitlab-ci file. Is there some method available for it?
before_script
export BRANCH_NAME=$CI_COMMIT_REF_NAME
// here I want to do something to extract the version
export Major=BRANCH_NAME.someoperation
export Minor=BRANCH_NAME.someoperation
export PATCH=BRANCH_NAME.someoperation
any other approaches are also welcome but I required the value in a separate variable which I can pass it to other operations.
I am new to gitlab-ci and working on it, thanks in advance.

Just split your string
You will find some examples here.
How to cut a string after a specific character in unix

Related

How to pass cypress environment variable from cucumber feature file?

I want to pass cypress environment variables from cucumber feature file. But while running scripts in cypress runner getting 404 NOT FOUND error.
Any Ideas please?
Versions used:
"cypress": "^9.5.4",
"cypress-cucumber-preprocessor": "^4.3.1"
Below, I show you how to use any variable within a feature file. You only have to replace the variable in the example (which is assetName) by your environment variable.
Feature: Business critical scenarios
Verify the proper operation of most critial scearnios
Scenario Outline: Add a asset successfully
Given I go to the Add Asset tab
When Validate page title and url
And I type the valid name <assetName> in the asset input box
Then I press send button
And Validate the asset <assetName> is added successfully
Examples:
| assetName |
| "ABCD0000000026" |
Notes:
In my example the variable within the section Examples and below the field assetName, it's in quotes because the expected variable in my test file and linked with those steps, it's a string. If you are using int you must skip the quotes.
If you add more values below ABCD0000000026, your test will run as many times as values you add, like a loop

Get current branch name

I'm running a script (bitbucket_pipelines.yml) and on one of the steps I need to know the current branch name, How can I get it?
I saw there is a predefined BITBUCKET_BRANCH variable, but I'm having troubles to print it so I can see its content.
I tried to do:
...
step:
script:
- echo $BITBUCKET_BRANCH
but when pipelines runs all I see is
echo $BITBUCKET_BRANCH
How can I really see the content of this variable?
I found that Bb Pipelines are sometimes picky when dealing with variables. Try changing this to echo "$BITBUCKET_BRANCH". Also, enclosing the whole line in single quotes might help.
#Shvalb, the question should be how to display the value of a variable in bitbucket pipeline.
I deal with bitbucket support on this matter before.
I want to echo a repo/pipeline variable to see the value and it is not showing correctly.
In my case, it was my repo variable conflict with my deployment/pipeline variable. However, from the support, I understand bitbucket is using search and replace the screen value to "hide" the actual value of the variable with direct echo.
in order to see the value, you can use
echo $VAR > /tmpfile
cat /tmpfile
It was the trick I used before but I am not sure whether it will still work.

Azure DevOps - pipeline variables - special char issue $$

I am using DevOps pipeline to build and deploy to different environments
For one environment I am encountering this issue where i am using a Pipeline Variable with $$ in the value
For Example:
Password pipeline variable with value = $omeCla$$Password
When i deploy it fails and when i check the logs the password is displayed as $omeCla$Password. So basically when $$ are together it drops one $
For all variable i am using regex __VaraibleValue__ and its working fine
I have tried:
$omeCla$\$Password to try and escape and it displays as $omeCla$\$Password . So basically \ doesn't work.
I tried '$omeCla$$Password' to try and escape and it displays as '$omeCla$Password'
I want to keep this value as a normal pipeline variable before review
So basically how can I escape this?
Or should I add a Secret Token here in the replace token task (see screenshot below)? and then make the pipeline variable secret? If so, what should I set for Secret Token? Also, in app.config in my repo what should I use instead of the regex __VariableName__ that I use for normal variables?
The solution was to use 4 $. So if you have $$ together you need to add $$$$
Example: $someCla$$$$Password
#JaneMa-MSFT as requested
https://developercommunity.visualstudio.com/content/problem/1296808/azure-pipeline-how-to-escape-special-characters-in.html

How to construct urls for job names for downloading latest artifacts in GitLab CI?

I am using the downloading latest artifact feature.
For me it is not clear, how the job name I need to pass is created: my job name contains e.g. spaces, equal signs and brackets:
build win: [USE_PYTHON=ON]
I know that spaces are replaced by +-signs but what about the others characters?
Changing the job name is not an option because I use the matrix-feature and it creates names like these.
Thanks a lot for your help!
Example ci yaml:
build win:
...
parallel:
matrix:
- USE_PYTHON: ["USE_PYTHON=ON", "USE_PYTHON=OFF"]
You can use ASCII encoding like for space %20.
Find them here
https://www.w3schools.com/tags/ref_urlencode.ASP

Using env variables in swagger.yaml in nodejs

Trying to figure out how can i access the env variable inside swagger.yaml configuration file.
The variable can be access inside the nodejs application using process.env.VARNAME. I want to use the same variable inside swagger.yaml file.
something like
definations:
myvariabledetail: "${process.env.VARNAME}"
. I already tried different combinations including "${process.env.VARNAME}",${process.env.VARNAME},${VARNAME} etc.
YAML as a text file format doesn't know anything about environment variables. A solution would be to load the YAML and then have code that uses a regex to find the environment variables and replace them with the current values. Then finally pass that resulting string into your YAML parser.
You can use envsub:
const envsub = require('envsub');
envsub({
templateFile: `${__dirname}/input.yml`,
outputFile: '/dev/null', // or filename to save result
})
.then(({ outputContents }) => console.log(outputContents));

Resources