Jenkins Groovy - 'op get item {item_name}' loops forever and doesn't return output
Hey,
I'm trying to use the cli tool to get an item data from a Groovy Script inside Jenkins.
Logging in and setting up the session token as a variable works just fine but when i get to the op get item {item}
the Groovy script is waiting forever and never returns.
I've tried:
- using the other wait functions that the Process object has, no success. ( see http://docs.groovy-lang.org/docs/groovy-1.7.2/html/groovy-jdk/java/lang/Process.html )
- do
timeout 25 op get item {item}
The process ends but there is no output passed to Groovy - do
echo exit | op get item {item}
The process immediately exits with no output - using
op get item {item}
inside a bash script and then run that through Groovy, process waits forever - pipe the output to a file, process waits forever
Note: If i do the command myself inside the machine, it works without any issue.
Tried with both my local Jenkins on Docker and a production Jenkins on Ubuntu 18.04
Please see an example of the code below:
/*****************************************************************************************/ def login_command = """ echo 'PASSWORD' | op signin {shorthand} --output=raw """ def execute_login = ["bash","-c", login_command].execute() execute_login.waitFor() def session_token = execute_login.text println session_token /*****************************************************************************************/ def export_session_token_command = """ export OP_SESSION_{shorthand}=$session_token """ def execute_session = ["bash","-c", export_session_token_command].execute() execute_session.waitFor() println execute_session.text /*****************************************************************************************/ def get_api_creds_command = 'op get item {item}' def execute_get_api = ["bash","-c", get_api_creds_command].execute() execute_get_api.waitFor() println execute_get_api.text /*****************************************************************************************/
Maybe this can help : https://stackoverflow.com/questions/5483830/process-waitfor-never-returns
Thanks!
1Password Version: 0.5.5
Extension Version: Not Provided
OS Version: Ubuntu 18.04
Sync Type: Not Provided
Comments
-
Good morning,
I've managed to find a workaround for this by using the following:
exec script -q -c 'op get item {item}' /var/tmp/result.log
0 -
This is very strange. I am not very familiar with Jenkins and the Groovy language it uses, but I am glad you found a workaround. I do not have an environment in which I can test this, but if you discover anything else about this, I am sure others would be interested to see what's going on here!
0