I was running my Acceptance test using IntelliJ
Unfortunately sometimes I get this Exception in IntelliJ executing specific task as this:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'SOME_VARIABLE' in value "classpath:/${SOME_VARIABLE}/acceptance-test.properties"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:180)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:126)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210)
at org.springframework.core.env.AbstractEnvironment.resolveRequiredPlaceholders(AbstractEnvironment.java:630)
at org.springframework.context.annotation.ConfigurationClassParser.processPropertySource(ConfigurationClassParser.java:461)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:280)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:207)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:175)
... 67 more
But, I would like to execute it using my terminal in macOS.
I know that, I can't to do it passing all variables as this manner!
SPRING_PROFILES_ACTIVE=xyz SPRING_CLOUD_CONFIG_URI=http://config-server EUREKA_SERVICE_URL=http=//eureka-server VAULT_PORT=8200 VAULT_AUTHENTICATION=TOKEN VAULT_TRUST_STORE_PWD=xxxxx VAULT_TRUST_STORE=file:/Users/joseluisbz/blabla.ts gradle app:acceptanceTest --stacktrace
Is it possible passing the same .env file in terminal?
Passing ENV values to gradle test is 2 layered
using ./gradle.properties or ~/.gradle/gradle.properties to setup the basic ENV variables. see https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
in the test { } block setup map of env values using either systemProperties or environment as per your need. see https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test
Related
I have created a custom environment variable as below in my environment-develop.properties file. I have set the value of
aws.access-key-id=${AWS_ACCESS_KEY_ID}
Trying to get the value as below:
System.out.println(environment.getProperty("aws.access-key-id"));
But this is not working. Error is:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'AWS_ACCESS_KEY_ID' in string value "${AWS_ACCESS_KEY_ID}"
How to obtain this value (set to abcd in Intellij's environment variable configuration)?
I am trying to set the serverless service name from the env file. Before deploying serverless, I have set the value of ECR_NAME as
export ECR_NAME=$(echo $CI_ENVIRONMENT_SLUG | awk -v srch="-" -v repl="" '{ gsub(srch,repl,$0); print $0 }')
Then I have written it as below in the serverless.yml.
service: ${env:CI_PROJECT_NAME}-${env:ECR_NAME}
useDotenv: true
configValidationMode: error
variablesResolutionMode: 20210326
Getting the below error:
Error:
Cannot resolve serverless.yml: "service" property is not accessible (configured behind variables which cannot be resolved at this stage)
Installed version
Framework Core: 3.14.0
Plugin: 6.2.1
SDK: 4.3.2
See Issue #9313 on GitHub:
https://github.com/serverless/serverless/issues/9813
Problem:
The latest version of the serverless framework is no longer working
for AWS Lambda deployments and is throwing the following error:
Cannot resolve serverless.yml: “provider.stage” property is not accessible (configured behind variables which cannot be resolved at this stage)
Discussion:
with the new resolver, such definition is not supported. In general,
it is discouraged to configure stage behind env variables for example,
as at the point where stage is going to be resolved, not whole env
might be available (e.g. loading env vars from .env.{stage} needs to
resolve stage first in order to properly load variables from file),
which might introduce bugs that are hard to debug. Also, the
provider.stage serves more as a "default" stage and --stage flag via
CLI is the preferred way of setting it.
...
In your configuration file you explicitly opt-in to use new resolver
via variablesResolutionMode: 20210326 variable.
We are not discouraging the use of env variables - quite the contrary,
we've been promoting them as a replacement for custom CLI options for
example and it is generally a great practice to use them. As for env
source for stage specifically, this has been introduced as a fix, as
stage should be already resolved before we attempt env variables
resolution, as loading .env files can depend on stage property.
#medikoo I know we've talked about it today, do you think it could be
safe to resolve stage from env source in specific circumstances (e.g.
when dotenv is not used)?
See also:
https://www.serverless.com/framework/docs/deprecations/#new-variables-resolver
https://www.serverless.com/framework/docs/providers/aws/guide/variables/
I am trying to use packagesbuild to create packages in MacOS. I want to use generic template with environment variable so that I don't require to create separate pkgproj file for each app but packagesbuild is not able to recognize the environment variable defined in the template file.
After setting the environment variable in the terminal
export APP_PATH='/Users/sachin/Documents/Test/Client/Example.app'
and then using the same environment variable in example.pkgproj
...
<key>PATH</key>
<string>${APP_PATH}</string>
...
then triggering the command packagesbuild using the projectfile
packagesbuild example.pkgproj
getting below eror
ERROR:
Description:
Unable to copy item at path 'APP_PATH' to
'/private/tmp/S2EyTxCb/502/ExampleClient' because the item could not be
found
http://s.sudre.free.fr/Software/Packages/about.html
I have a few different environments in which I am running Cypress tests (i.e. envA, envB, envC)
I run the tests like so:
npm run cypress:open -- --env apiEndpoint=https://app-envA.mySite.com
npm run cypress:open -- --env apiEndpoint=https://app-envB.mySite.com
npm run cypress:open -- --env apiEndpoint=https://app-envC.mySite.com
As you can see, the apiEndpoint varies based on the environment.
In one of my Cypress tests, I am testing a value that changes based on the environment being tested.
For example:
expect(resourceTiming.name).to.eq('https://cdn-envA.net/myPage.html')
As you can see the text envA appears in this assertion.
The issue I'm facing is that if I run this test in envB, it will fail like so:
Expected: expect(resourceTiming.name).to.eq('https://cdn-envB.net/myPage.html')
Actual: expect(resourceTiming.name).to.eq('https://cdn-envA.net/myPage.html')
My question is - how can I update the spec files so that the correct URL is asserted when I run in the different environments?
I am wondering if there's a way to pass a value from the command line to the spec file to tell the spec file which environment I'm in, but I'm not sure if that's possible.
You can directly use the Cypress.env('apiEndpoint') in your assertions, so that whatever you're passing via CLI, your spec files has the same value -
expect(resourceTiming.name).to.eq(Cypress.env('apiEndpoint'))
And if you want to check that when you pass https://app-envA.mySite.com and the url you expect in the spec file is https://cdn-envA.net/myPage.html, You can use:
expect(resourceTiming.name).to.eq(Cypress.env('apiEndpoint').replace('app', 'cdn').replace('mySite.com', 'net') + '/myPage.html')
Your best bet, in my opinion, is to utilize environment configs (envA.json, envB.json, etc)
Keep all of the property names in the configs identical, and then apply the values based on the environment:
// envA.json file
"env": {
"baseUrl": "yourUrlForEnvA.com"
}
// envB.json file
"env": {
"baseUrl": "yourUrlForEnvB.com"
}
That way, you can call Cypress.env('baseUrl') in your test, and no matter what, the right property should be loaded in.
You would call your environment from the command line with the following syntax:
"cypress run --config-file cypress\\config\\envA.json",
This sets up the test run to grab the right config from the start.
Calling the url for login, for example, would be something like:
cy.login(Cypress.env('baseUrl'))
Best of luck to you!
I'm using Spring Boot with embedded tomcat, everything worked fine and suddenly I got the error :
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to create tempDir. java.io.tmpdir is set to C:\Windows\
at org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory.createTempDir(AbstractEmbeddedServletContainerFactory.java:183)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:165)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
... 11 common frames omitted
Caused by: java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(File.java:2024)
at java.io.File.createTempFile(File.java:2070)
at org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory.createTempDir(AbstractEmbeddedServletContainerFactory.java:174)
... 14 common frames omitted
I didn't do any manipulations with user or system variables.
My TEMP user variable is looking on C:/Users/me/AppData/Local/Temp , and I guess tomcat has to use this value insted of system one, which is actually C:/Windows/Temp
If you use IDEA check "Include parent environment variables" in Environment Variables window in the Run/Debug Configuration.
On Windows GetTempPathA is used to locate temp directory. Algorithm:
1. The path specified by the TMP environment variable.
2. The path specified by the TEMP environment variable.
3. The path specified by the USERPROFILE environment variable.
4. The Windows directory.
So if your app is started without TMP & TEMP & USERPROFILE defined you'll get java.io.tmpdir == c:\Windows (https://learn.microsoft.com/en-us/windows/desktop/api/sysinfoapi/nf-sysinfoapi-getwindowsdirectorya).
Typically applications set java.io.tmpdir inside app-run.bat (via -D...=...) or app.properties.
I hit this problem because Gradle Test task won't pass environment variables if environment properties aren't passed but replaced:
test {
environment = ["A": "1", "B": "2"] // won't work, because it replaces envs
}
test {
environment( ["A": "1", "B": "2"] ) // will work, because it appends to existing envs
}
I observed the following behaviour
changed all out of a sudden
works if run from commandline as self-contained jar
fails when run from IntelliJ (2018.1)
As a quick workaround i explicitly added -Djava.io.tmpdir=$EXISING_DIR_WITH_WRITE_ACCESS as JVM parameter in run configurations.
If you use eclipse check "Append to environment variables" in Environment Variables window in the Run/Debug Configuration.
Thanks to #max answer above
I was using JAVA EE eclipse - photon
In my case the problem occurred when I changed my default workspace library from [jre.1.8.0_121] to [jdk.1.8.0_121]. Setting it back to jre seems to have fixed the problem.