How to use a system environment variable in init.gradle - environment-variables

We are migrating our builds over to gradle and I used to have an external script for deploying that referenced some system environment variables. Am I able to reference them in my init.gradle and how do I access them?

Environment variables are accessed in the usual Java way: System.getenv() to get all of them, and System.getenv("foo") to get a particular one.

Related

How to unset (or hide) all environment variables prior to starting pytest

In Jenkins, I am running my pytests inside of a Docker container that has several environment variables set. Before running ANY tests, I would like to ensure that these environment variables are empty or not-available to the code running in the tests.
Why do this?
I want to understand the dependencies of my source code on the environment variables. If a chunk of code requires an environment variable be set, I would prefer to explicitly set/mock it.
I want developers to be able to easily run the tests locally in their IDE without needing to do complex env setup. Right now people frequently add code that depends on the environment variables which causes the tests to break when running locally.
Is there a pytest fixture that I should consider using to unset or hide all environment variables?

How to set Global Environment Variables from a file in Jenkins

I am new to Jenkin pardon me for any wrong statements.
I have to set Global Environment Variables from a File(say config or txt) and I want to place that file either in my local or somewhere on the server.
I have gone through some documentations but it all says to use EnvInject Plugin which is basically helps for a specific job when we are building it.
But I want a solution where Global env variables can fetch from the file so that Configure System page can load quickly.
I'm assuming that you are looking to read properties from a specific file and inject them as environment variables to your jenkins job.
You can follow below approach:
Create property file like env.properties with below content:
testvalue='mytest'
Sample code to read the file and inject read variables as environment variables
node`{load "${WORKSPACE}\env.properties"
echo "test value: ${testvalue}"
}

Read TFS build variables from file

Is it possible to read a file from the git source control and set values to TFS build variables so that we can use them in other steps?
We have a file with the version info and the branch (VER_TYPE=3 is DEV) that we use to set up assembly version together with the build number
VER_MAJOR=2018
VER_MINOR=1
VER_TYPE=3
Tks in advance!
It's possible to define or modify a variable from a script, use the task.setvariable logging command.
Sets a variable in the variable service of taskcontext. The first
task can set a variable, and following tasks are able to use the
variable. The variable is exposed to the following tasks as an
environment variable.
When issecret is set to true, the value of the variable will be saved
as secret and masked out from log. Secret variables are not passed
into tasks as environment variables and must be passed as inputs.
Examples:
##vso[task.setvariable variable=testvar;]testvalue
##vso[task.setvariable variable=testvar;issecret=true;]testvalue
More details please refer Define and modify your variables in a script
You can run a script on windows agent using either a Batch script task or PowerShell script task. You just need to read the specific file in source control, download it in the workspace on the build agent. Then read the file, a way using powershell for your reference: Read file line by line in PowerShell

Using Environment Variables for MsDeploy package

I'm trying to setup something with WebDeploy that will allow configuration of Environment Variables to set the "parameters.xml" parameters in a web deploy package.
From what I've read so far, this should be possible, but I've not had any success yet.
Essentially, it's TeamCity that I'm using to do it, but the concept is beyond a usage in TeamCity.
I'm using the generated cmd that you get from using the /t:Package target.
So my question is, is this possible? or is there another solution for iterating the teamcity variables and updating the SetParameters.xml (rather than manually coding an XML Poke foreach, or using /property syntax on the raw MsDeploy.exe).
You should be able to reference environment variables from the command line when you run the msdeploy command. I don't have experience with TeamCity but I suspect you give it a msdeploy.exe command to run.
This post gives more details - http://evolutionarydeveloper.blogspot.com/2013/05/specifying-environment-variables-at.html

JENKINS_HOME environment variable used for 2 conflicting purposes

It appears that Jenkins is using the environment variable $JENKINS_HOME for 2 different purposes, and for each purpose it will get a different value.
Purpose#1: First, there is the JENKINS_HOME that is a directory on the local file system that stores files that Jenkins creates. Jenkins uses this directory for disk space to perform builds and keep archive. So a sample value might be:
export JENKINS_HOME=/var/jenkins
That purpose is described here:
https://wiki.jenkins-ci.org/display/JENKINS/Tomcat
https://wiki.jenkins-ci.org/display/JENKINS/Administering+Jenkins
Purpose#2:
There is another instance where Jenkins used the JENKINS_HOME environment variable, and that is for monitoring external jobs. But this time JENKINS_HOME is a URL, like such:
export JENKINS_HOME=http://user:pw#myserver.acme.org/path/to/jenkins/
That purpose is described here:
https://wiki.jenkins-ci.org/display/JENKINS/Monitoring+external+jobs
So it seems odd that Jenkins would use the same environment variable, yet its value will change depending on the purpose. I would think that the external job would use another name for the environment variable, like JENKINS_URL. I suppose as a workaround I can just set the environment variable in the Servlet container (Tomcat for me) instead of on the operating system, so there is no conflict. Still though, the fact that this conflict for the variable exists in the first place seems strange. Is there something I'm missing?
That is pretty confusing, but the second purpose is for monitoring Jenkins jobs in an external process, not within Jenkins itself; so it's not Jenkins that is using the $JENKINS_HOME value in this case and there is no conflict. They could have picked a better name for the variable, though.
In most other cases, the Jenkins master URL is referred to as JENKINS_URL - see the Jenkins CLI documentation for example.

Resources