I am trying to replace env variables used by AspnetCore by defining them in .gitlab-ci.yml file.
appsettings.json file looks like this:
"ConnectionStrings": {
"DatabaseConnection": "my-connection-string"
},
Here are some things i tried.
Invalid Yml:
ConnectionStrings:
DatabaseConnection: "my-connection-string"
Valid Yml (Not working):
"ConnectionStrings:DatabaseConnection": "my-connection-string"
"ConnectionStrings::DatabaseConnection": "my-connection-string"
For last two i ger this error and as you can see it is all transformed into one long string instead of key value pair for env varijable:
/bin/bash: line 87: export:
`ConnectionStrings::DatabaseConnection=Server=mssql,1433;Database=MyDatabase;User
Id=SA;Password=MyPassword;Trusted_Connection=False;MultipleActiveResultSets=True':
not a valid identifier
I am using linux runner for CI.
Looks like you're trying to replace the database connection depending on the environment. You could use some strategies like configure variables
"ConnectionStrings": {
"DatabaseConnection": "$CONNECT_ENV"
},
where you could have one per environment for instance $CONNECT_INT, $CONNECT_QA, $CONNECT_PROD and configure each one of these variables properly (variables part of .gitlab-ci.yml)
variables:
CONNECT_INT : "ConnectionStrings::DatabaseConnection=Server=mssql,1433;Database=DB_INTEGRATION_PROD;User Id=SA;Password=MyPassword;Trusted_Connection=False;MultipleActiveResultSets=True"
Or you could have multiple files per environment, CONSTRING_INT.conf, CONSTRING_PROD, and replace it depending on the environment.
Or you could replace the connection string using shell commands. https://unix.stackexchange.com/questions/226005/how-can-i-replace-a-specific-string-within-a-line-inside-a-text-file
An example of a real project we're using 1
[Real example of one project]1
Related
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
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
I searched all the docs about Output Variables are for build pipeline and only told me how to set in .yaml. But how to use it in release pipeline?
Supposed I have 2 variables $abc="123" $def="456" in step Login. How to set them in below text box? and How to use them in step Deploy?
Some tasks define output variables
For brief text, it represents the follow scripts:
echo "##vso[task.setvariable variable=abc;isOutput=true]123"
Just specify the reference name in the blank of task, and then, you can call this output variable abc by using the format: <reference name>.<variable name>.
For example, if you specify the reference name as mycustom, just call the output variable by using $(mycustom.abc).
Is there a way I can input variable values from outside to terraform main file. It can be a excel sheet or sql db. Is it possible to do so ?
What you can't currently do is point you cmdline at a db i.e. to replace a tfvars file, but what you can set up in Terraform is to use a number of different key value stores:
consul
https://www.terraform.io/intro/examples/consul.html
aws parameter store (using a resource or data)
https://www.terraform.io/docs/providers/aws/d/ssm_parameter.html
There are quite a number of other key/value stores to choose from but there's no zero code solution and you will end up with lots of these statements:
Setup a key in Consul to provide inputs
data "consul_keys" "input" {
key {
name = "size"
path = "tf_test/size"
default = "m1.small"
}
}
There are many ways to do that;
You can use a tfvars file with all your inputs and you can use one file customer, user, environment
You can pass the variables to terraform executable on the command line
You can define environment files prefixed wit TF_VAR_[variable]
You can use https://www.terraform.io/docs/providers/aws/d/ssm_parameter.html as suggested above
You can even store variables in DynamoDB or any other database
You can use Consult+Vault as well
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));