2

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 =)

1
  • 1
    could you get an answer to this question? I have similar scenario and looking for an apt solution for it. I was also trying System.getenv but does not seem to work. In y case, my jenkins job is parameterized and I try to get that parameter value in java code in my android app Commented Aug 9, 2016 at 8:50

3 Answers 3

1

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")
Sign up to request clarification or add additional context in comments.

1 Comment

Since the OP wants to fetch the value, I would think get("PARAM_NAME") is a better suggestion than containsKey("PARAM_NAME"), which in this case only determines whether a build-parameter named "PARAM_NAME" exists.
0

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

1 Comment

can you provide me with some example?
0

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

4 Comments

Yes, it looks like I looking for, but I can't find any useful article how i can get values(of environment variables) in java code.
You can use System.getenv("PARAM_NAME"); if you used the plugin to inject the variable into the environment. Or maybe System.getProperty("PARAM_NAME")
1. I've enable " Inject environment variables to the build process" section. 2. Then I've add "TEST_STRING=hello world" in "Properties Content". 3. In MainActivity class I've add "System.getenv("TEST_STRING")". And when I build application, I see that value returned by System.getenv("TEST_STRING") is "null". what I did wrong?
@IvanB... could you get an answer to this question? I have similar scenario and looking for an apt solution for it. I was also trying System.getenv but does not seem to work. In y case, my jenkins job is parameterized and I try to get that parameter value in java code in my android app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.