Ivan B
Ivan B

Reputation: 414

Get Jenkins build parameter inside java code

I have a question about build parameters in Jenkins.

I want add build parameter (url) on Jenkins, and write there any URL, and then use it in code.

Is it posible, and if it is, how I can do this?

System.getenv("PARAM_NAME"); isn't working for me.

Thanks a lot =)

Upvotes: 2

Views: 3425

Answers (3)

mainframer
mainframer

Reputation: 22149

If you are writing java code or jenkins plugin for instance, you can simply do this:

import hudson.model.AbstractProject;
AbstractProject job.getLastBuild().getBuildVariables().containsKey("PARAM_NAME")

Upvotes: 1

S.Spieker
S.Spieker

Reputation: 7385

I think you are looking for the EnvInject+Plugin.

Some use cases

  • To remove inherited environment variables (PATH, ANT_HOME, ...) at node level (master/slave), available by default for a job run.
  • To inject variables in the first step of the job (before the SCM checkout)
  • To inject variables based on user parameter values
  • To execute an initialization script before a SCM checkout.
  • To execute an initialization script after a SCM checkout
  • To inject variables as a build step obtained from a file filled in by a previous build step
  • To know environment variables used for a build

Upvotes: 0

Gabe Sechan
Gabe Sechan

Reputation: 93728

You could have jenkins modify your values.xml file before compiling. That would be the easiest way I can quickly think of.

Upvotes: 0

Related Questions