Use Environment variable in job description - jenkins

I'm trying to set dynamically a job description with a global environment variable.
But I cannot use $MYVAR or ${MYVAR}.
Does anybody have an idea ?
Thanks !

As a temporary solution, I am using the "Anything Goes" formatter plugin.
In my job description, i'm using :
<iframe src="http:/JENKINS_URL/Docs/DocsJenkins/MY_DATA.html"></iframe>
I created an alias in IIS referencing a folder with some html pages. And i'm setting dynamicaly this pages with my global enviromnent variables.
Hope this tricks can help somebody else.

You should install Environment Injector Plugin.
After installation, go to your job configuration page,then
Build Environment ==> Inject environment variables to the build process ==> Properties Content
Define your environment with KEY=VALUE format:
Then, this variable can be accessed by surrounded by ${}

Related

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}"
}

How do I get a list of all macros in Jenkins?

How do I access the current date as a macro in Jenkins?
Caused by: org.jenkinsci.plugins.tokenmacro.MacroEvaluationException: Unrecognized macro 'BUILD_TIMESTAMP' in 'sprint5-${BUILD_TIMESTAMP}'
${DATE} didn't work either. Nothing in the glossary about macro. https://jenkins.io/doc/book/glossary/
No useful search results. https://duckduckgo.com/?q=jenkins+date+macro&ia=web
You find all available environment variables here, on Jenkins wiki.
Other plugins may define additional macros.
You can check all default environment variables on http://<JENKINS_IP>:<JENKINS_PORT>/env-vars.html or from official page.
By default there is no time environment variable. Previously it could be possible to use ${BUILD_ID}, but now it is identical to ${BUILD_NUMBER} for builds created in 1.597+ Jenkins.
For using ${BUILD_TIMESTAMP} environment variable in your job, you need to install (and configure) Build Timestamp Plugin.
Note: I cannot check if you can use that plugin in Version Label Format step exactly, so probably you can also look at Zentimestamp Plugin.

How to edit a file with environment variables in jenkins

I'm bit new to jenkins. What I want is to edit config files with environment variables of jenkins. I tried ant scripts, Nant plugin but all ended up with errors. If anyone knows something about this please help. For example lets think we want to replace word "hello" in C:\files\test.txt to "bye". word "bye" should be taken from a environment variable of jenkins. Thanks
Best is to utilize Jenkins EnvInject plugin. With that you can have a build step to manipulate/generate your properties, and then you can add another build step to load these properties into project environment variables.
See this stackoverflow question for a more detailed example.

Jenkins EnvInject from a file which is a Job parameter by itself

I've got a Job Parameter, for example PROPERTIES_FILE.
I want to inject all Env Variables from that file into my job session, using the EnvInject plugin.
Is there a way to do that?
I managed to inject variables
only for a hard coded file path, and not from a parameter.
EnvFile plugin (not EnvInject) seems to support variables in the properties file path (as it uses $WORKSPACE in the example).
Also, if you are on Windows, maybe all you need for EnvInject plugin to work is to use $param for variable, not %param%. While the scripts need %% notation, inside Jenkins still uses $

Jenkins deploy plugin - pass parameters from properties file

I'm using Jenkins and deploy plugin, with which I'm deploying to tomcat server. How can I pass parameters from properties file to this deploy plugin?
for example I want to pass my property app.server.url to Tomcat URL field.
I tried to pass $app.server.url also %app.server.url%, but that doesn't work.
I am assuming you have a properties file in the format app.server.url=somevalue
You then can inject these properties into the Jenkins environment using EnvInjec Plugin. Use Inject environment variables for your job build step, and just specify your file path (leave the content field blank). After that, you can reference it like this $app.server.url for *nix, or %app.server.url% for Windows. However this only works on the shell level. On the plugin properties level, a lot of plugins are expecting properties only in *nix-style format.
The further problem is that *nix-style variables do not allow dots .. So $app.server.url is not valid on *nix. I do not know if it will work on plugin-level on Windows though.
So after setting up EnvInject plugin, try the following two:
Try using $app.server.url in your deploy plugin.
Else change the property file to something like app_server_url=somevalue, and then try $app_server_url in deploy plugin.

Resources