How to make a Java console output a environment variable in Jenkins? -


i new jenkins , though found few similar questions, none of solutions seemed work me way need to. might basic problem me it's big deal i'm struggling with.

basically, built project executes java selenium code, displays session id in jenkins' console output , that's need add environment variables used in projects triggered after completion of one.

i tried groovy scripts don't think understand enough how work , whatever given, wasn't hoped get.

has done similar provide tips on how achieve that?

many thanks

there 2 options (in theory, 1 of them doesn't work, see 2. below) depending on whether printing under control or not.

  1. printing under control:

    • write session id properties file, e.g. from-build-log.properties:

      sessionid=... 
    • add post-build actiontrigger parameterized build on other projects

      this plugin triggers builds on other projects, parameters predefined, or supplied finished build.

      every parameter passed target project(s), if target not parameterized, or if no property of name defined.

      • add parametersparameters properties file
        • use properties file: from-build-log.properties
  2. printing not under control:

    • add post-build actionpost build task:

      this feature allows associate shell or batch scripts perform tasks on hudson depending on build log output. if log text matches somewhere in build log file, script execute. [...]

      java regex allowed, , groups can used script parameters. if text "last build : #(\d+)" , script "script.sh", if log contains line "last build : #4", script "script.sh 4" called.

      • tasksscript:

        [...] references %1, .. %n allowed, , replaced groups matched regex. %0 whole match.


      unfortunately doesn't work since there issue known since 2013: [jenkins-17268] post build task plugin: passing arguments not work documented.

      • buildexecute windows batch commandcommand:

        @echo( & echo   cmd: sessionid=123456789 
      • post build tasktasks:

        • log text: sessionid=(\d+)
        • script:

          @echo( & echo   sessionid='%1'(!) of '%0' 

      console output:

      ... [freestyle-project] $ cmd /c call c:\windows\temp\hudson4684581005071706054.bat    cmd: sessionid=123456789  c:\program files (x86)\jenkins\workspace\freestyle-project>exit 0  performing post build task... match found :sessionid=(\d+) : true logical operation result true running script  : @echo( & echo   sessionid='%1'(!) of '%0'  [freestyle-project] $ cmd /c call c:\windows\temp\hudson1525182929053902824.bat    sessionid=''(!) of 'c:\windows\temp\hudson1525182929053902824.bat'  c:\program files (x86)\jenkins\workspace\freestyle-project>exit 0  post build task : success end of post build task : 0 finished: success 

      %0 not "the whole match" script's name, usual windows command line. %1 empty.


      a workaround is:

    • add build stepexecute shellcommand:

      sed -en 's/.*(sessionid=[0-9]+)/\1/p' \   ../../jobs/${job_name}/builds/${build_number}/log > from-build-log.properties 
    • add post-build actiontrigger parameterized build on other projects

      • add parametersparameters properties file
        • use properties file: from-build-log.properties

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -