Is there a way to pass all Gradle properties kept in the GitLab Enviroment variable,
let's say I will create a Variable ALL_IN_FOR_GRADLE with the following key=value pairs
A=V1
B=V2
using these key- values in
./gradlew e2e <PROPERTIES>
You can set the GRADLE_OPTS environment variable which is the standard way to configure gradle using environment variables. You can also expand variables within variables, so you could compose GRADLE_OPTS from other variables in your GitLab .gitlab-ci.yml configuration:
variables:
GRADLE_OPTS: $ALL_IN_FOR_GRADLE
# OR
GRADLE_OPTS: "org.gradle.foo=bacon org.gradle.bar=eggs"
Alternatively, you can create a file type variable for the gradle.properties file... however this would likely conflict with repos which commit their own gradle.properties so I would not recommend that.
Related
I'm using GitLab CI Auto DevOps to compile a project based on Maven based in a DinD (docker-in-docker) runner.
CI job start, and buildpack for Maven is correctly detected (based on herokuish).
How can I configure a custom settings file without switching to a custom .gitlab-ci.yml?
I would like to continue using Auto DevOps.
Because maven needs access to a private repository based on Nexus it is convenient to configure a custom settings.xml (and version it with your source code)
The easiest solution is to include a custom settings.xml. This feature was included in the corresponding buildpack used by Auto DevOps some time ago, as you can see in this article from Heroku buildpacks about "Using a Custom Maven Settings File".
So I defined MAVEN_SETTINGS_PATH variable in .gitlab-ci.yml config file:
variables:
- MAVEN_SETTINGS_PATH: ".m2/settings.xml"
Then, included the file settings.xml in the repository.
Avoid to include secrets or another sensible information
When using a private maven repository with credentials
Finally, you can define in Gitlab some variables to be used in settings.xml. Using Gitlab UI or API add variables for the user, password, and repository url, to be included as environment variables from Gitlab into the job. Then you can use it in settingx.xml like ${env.VARIABLE_NAME}
Example of Gitlab-CI configuration file:
include:
- template: Auto-DevOps.gitlab-ci.yml
variables:
MAVEN_SETTINGS_PATH: ".m2/settings.xml"
AUTO_DEVOPS_BUILD_IMAGE_FORWARDED_CI_VARIABLES: NEXUS_REPO_USER,NEXUS_REPO_PASSWORD,NEXUS_REPO_URL
As a final recommendation, you should avoid to use passwords in environment variables, use native methods from your environment for credentials storage is recommended.
I am trying to parameterize my build.gradle file with variables from my applications.properties file. Let's say I have a variable: flyway.user that is set in application.properties. How can I include this in the build.gradle file?
My view - This is the other way around.
Gradle build + flyway - would only apply in local DEV / CI build.
All other ENV will drive via non-gradle tools.
its better to keep ENV defined in GRADLE_HOME (~/.gradle) gradle.properties
During build these are available in gradle project - to all tasks
Also - you can tokenise the application.properties and replace values (for DEV)
additional benefit is that if multiple developers are working - each can have their own config without any code change.
~/.gradle/gradle.properties >> gradle :project >> tasks (flyway, processResources)
(I use the above - for my flyway in our team)
I have a properties file in my workspace which is not a groovy file , and data is in the format
var1=var1
var2=var2
How do I define the steps('Declarative') in a stage to inject these values as environment variable for the whole pipeline?
Have you checked the accepted answer to How to read properties file from Jenkins 2.0 pipeline script ? Sounds exactly like your problem.
I have created a Maven Run Configuration in Intellij (Community Edition, Mac, Yosemite), and want to set up an Environmental Variable in the "Runner" tab of the configuration. In the value of that variable, I was wanting to use a parent environmental variable (specifically, $HOME) for part of the value.
For example:
Run > Edit Configuration > Add New > Maven > Runner (tab) > Environmental Variables > Add New:
name: SOME_CONFIG_FILE
value: $HOME/.config/file.json
I have tried with HOME, $HOME, $HOME$, ${HOME} and %HOME% and none of them were able to resolve properly. Clicking on the "Show" for the Parent Environmental Variables show HOME with the proper value.
What is the correct way to set the value?
It's not supported at the moment:
IDEA-85313 Provide ability to reference parent environment variables in Run Configuration dialog
I know I can't set environment variable directly from Gradle, but is there some other solution?. I need to do this:
do some stuff..
set 4 environment variables (their values depend on some settings)
run some ant scripts (that depend on environment variables)
I thought of creating a file (.setenvironment) with all the settings I need, and then source it from Gradle (source .setenvironment), but I fear that I wouldn't be able to reset the variables if something goes wrong (and I need to set "JAVA_HOME", for instance, which is also important for the build scripts themself).
You can't set environment variables from java and other JVM languages. The only way of doing it is via ProcessBuilder.
You can also set the variables before gradle is run.