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
Related
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
I'm working on automating deployment for dev and prod with sqoop jobs that have to be scped onto specific servers for each type. With these jobs, the scripts associated for each sqoop job needs to change based on dev vs prod. Currently, I have a git repo containing a dev and prod folder where approved dev changes are put onto the prod folder but with the variables (references to dev database vs prod database) changed. Then I have two jenkins pipelines that associate with each and have independent triggers. This is incredibly hacky.
My current plan is to consolidate into a single folder and replace all the variables with a pseudo variable such as %DBPREFIX% and then having each associated pipeline regex and replace all matches with its associated database prefix on compilation.
The files that need to be changed are shell scripts and hive scripts, so I can't just define a environment variable within the Jenkins node shell.
Is there a better way to handle this?
tl;dr: I need to set variables in different files that can be automatically changed through a jenkins pipeline.
You can actually reference environment variables in shell scripts and in hive scripts.
in a shell script to reference $HOT_VAR:
echo $HOT_VAR
in a hive script to reference $HOT_VAR:
select * from foo where day >= '${env:HOT_VAR}'
i'm not sure if that is an example of a hive script. maybe you want to see https://stackoverflow.com/a/12485751/6090676. :)
if you are really unable to use environment variables for some reason, you could use command line tools like awk, sed, or perl (why do people always suggest perl instead of ruby?) to search and replace in the files you need to configure (based on environment variables, probably).
Outside of chaining separate Jenkins builds together, is there a way within a single build to get credentials (via binding or otherwise) or Injected Passwords available for use within the Promoted Builds plugin?
I'm using other environment variables that I wrote to a file in my build step and then read in using the Inject environment variables, but I was not looking to repeat that for a secret used at deploy/promotion time.
Note: I am using Jenkins 2.45
Thanks!
Unfortunately, this doesn't look possible, it is marked as a bug in the Jenkins tracker:
JENKINS-14169 Injected env variables not available for use in processing promotion.
I have a job in Jenkins and want the groovy script for the same? Is there a way I can do that?
I have created a Job using Jenkins, like add shell Command, Sync from repo,etc. Now I wish to have groovy script for the same, but I dont want to go to the trouble of writing the entire thing again. Is there something like Export to .groovy?
P.S. I am not sure of the correct tags.
You want to copy your configuration using Groovy script to create a new job or to persist.
Below Links are helpful for clone/ copy and create jobs using groovy script.
http://jenkins-ci.361315.n4.nabble.com/How-to-Copy-Clone-a-Job-via-Groovy-td4097412.html
Can I use Jenkins CLI or some groovy scripts to create a new job
https://wiki.jenkins-ci.org/display/JENKINS/Clone+all+projects+in+a+View
In case you want to persist your Job, always backup your resources file such as config.xml, jenkins.xml,etc..
you can recreate job from config.xml which holds all your job configuration
Check out this plugin. It seems to be appropriate for your purpose. Though it has some restrictions for plugins in your jobs that are not capable of Pipeline syntax. Anyway, it could be useful for code generation.
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