fetching parameters from a jenkins job in java code

前端 未结 3 885
广开言路
广开言路 2021-01-22 05:44

I have a parameterised jenkins job that is accessing my plugin. Inside plugin\'s code in java, i require these parameters using which i have to trigger another job in jenkins. I

相关标签:
3条回答
  • 2021-01-22 05:51

    One of the option to achieve this is "PASS and GET AS ARGUMENT" in your java code.

    Jenkins's variables value can be retrieved like this.

    urlValue=${url} 
    

    Then pass this value in java code. This will be structure of your Execute shell in job configuration.

    #!/bin/bash -e
    urlValue=${url} 
    # run java code
    java <classNameToRun> $urlValue
    
    0 讨论(0)
  • 2021-01-22 05:52

    Thanks for the suggestions, but it worked when i did the following: I hit the

    JENKINS_HOST_URL/job/JENKINS_SEED_JOB_NAME/api/json?pretty=true
    

    and found the current build number, thereafter, hitting jenkins again with this number(JENKINS_HOST_URL/job/JENKINS_SEED_JOB_NAME/currBuildNum/api/json?pretty=true),

    I was able to fetch all the parameters passed in there in this build.

    0 讨论(0)
  • 2021-01-22 05:54

    To the best of my knowledge, Jenkins parameters are exposed as environment variables. However, if you use a build system like Maven that launches Java sub-processes, those variables might not be inherited.

    Probably your most reliable approach is to explicitly pass parameters as system properties in your Jenkins configuration, eg -DREPOS=${REPOS}

    0 讨论(0)
提交回复
热议问题