Setting environment variables for different environments in CircleCI - circleci

Is there a better way to set environment variables for secrets for dev, staging, prod etc than DEV_SECRET_KEY and PROD_SECRET_KEY? Is the best way to just use a prefix for each environment?

You should use CircleCI Contexts.
Create a context for each environment, and then each context would have SECRET_KEY set but the value will be specifically for that environment in that context.

Related

What is the best way to use user environment in Jenkins?

I have Jenkins set up on MacOS and want to execute commands that are installed on my user (e.g. Ruby, cucumber). Unfortunately, Jenkins does not use Environment vars of current user, so all installed programs does not work correctly (such as Ruby, and its dependencies).
For example, for Ruby and Cucumber I have to manually specify all necessary envs vars, including the $PATH
Is there a correct way to use current user environment without manual ENV set up or EnvInject plugin or the environment {} block in jenkinsfile?
I want that all vars user environment and system environment variables would be accessible in Jenkins job without manual updating of environment every time I install new package

Setting environment variables for Jenkins slaves

New to jenkins and looking to create a job. I need to use the IP of my Jenkins Instance in part of my Java Code. Is there an existing environment variable that I can use or do I have to add one myself? If so, how exactly can I do this? The slaves are ec2 instances. I looked at some similar questions posted here but it seems they are talking about the master rather than the slaves. Thanks!
EDIT: To confirm, external requests will be sent to the IP that I set in my Java code
I do not think there is any such environment variable in the default list of jenkins Environment variables.
One way to set IP as environment variable on a slave is:
Go to the slaves configuration page
Under "Node properties" there is a section called "Environment Variables"
Add a new Environment variable, e.g. IP_ADDRESS with value = the ip of that slave.
You should be able to access it from jenkins job, just like any other environment variable. e.g. in a Shell build step ${IP_ADDRESS}

Jenkins Blueocean - same Jenkinsfile across multiple environments while passing different values of environment variables

I do not want to put my environment variables in the source code, i know we can add variables in Jenkinsfile.
How can i pass environment variable via the Jenkins job/UI while using Jenkins Blueocean?
This needs to be done in a way so that I can use same Jenkinsfile across multiple environments while passing different values of environment variables.

Jenkins environment variables plugin

I'm looking for a way to create a properties file that will include all environment variables of my application. The idea is to create a file when deploying with jenkins and then use a script to populate the env vars in the AWS instance that the deployment takes place via a codedeploy hook.
What I want to simulate is the heroku experience, where there is a screen with all the env vars as key-value pairs. Is there such a plugin? Right now I'm using a shell script to create the file by echoing the key-value pairs, which works just fine, but I'd prefer something more user friendly.
Have a look at this ENVINJECT plugin this might suit your requirement

How to make Jenkins use already existing environment variables set on a slave node?

I am making use of a batch script that is supposed to run on a slave node, which makes use of Sahi. The environment variable for Sahi is set as 'SAHI_HOME' on the node.
When I run the batch I figure out, it is not able to locate Sahi classes.
How do I enforce Jenkins to make use of environment variables set on the slave? I mean is there any way to fetch environment variables set on a slave node?
We got around this issue by installing and updating Sahi automatically. There is a nice Jenkins Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Custom+Tools+Plugin
You just need to place a Sahi Zip somewhere for Jenkis to access. The custom tool plugin automatically unpacks archives and creates a toolname_HOME environment variable.
Just name your tool SAHI and you have Sahi and $SAHI_HOME on every job and node you need.
Regards
Wormi
I ran into a similar issue with my AIX slaves. The issue is that the .profile file is not executed when a non-interactive shell is started. Therefore, you have several options.
Make sure that the environment variable is set in the environment file (in AIX, I can set the ENV variable to a filename that will be executed for both interactive and non-interactive shells.) I think the .kshrc file might qualify too.
Set the environment variable in the node configuration
set the environment variable in the master configuration
set the environment variable in the job (needs env inject plugin)
set the environment variable explicitly in the bash script

Resources