sdkman / sdkman-cli

The SDKMAN! Command Line Interface
https://sdkman.io
Apache License 2.0
6.05k stars 628 forks source link

Using sdkman on CI server with login shell #548

Open jglapa opened 7 years ago

jglapa commented 7 years ago

I'm using sdkman together with continous integration jenkins server. The level of freedom it gives us tremendous since it allows us to choose any given grails, gradle version for any job we want dynamically. We use it in a simple manner. We execute a bash script with -elx switches and then just set what we want using sdk u candidate version + the actual command to execute. This works most of the time great but very often the jobs are failing because sdkman wants to selfupdate although I have set it to offline mode. Any idea what can be the reason? I've verified in the config that sdkman_auto_selfupdate=false and that's about correct? and excerpt from the logs:

+ [[ -h /var/lib/jenkins/.sdkman/candidates/grails/current ]]
+ echo ''

+ __sdkman_echo_green 'Using grails version 2.4.5 in this shell.'
+ __sdkman_echo 32m 'Using grails version 2.4.5 in this shell.'
+ [[ false == \f\a\l\s\e ]]
+ echo -e 'Using grails version 2.4.5 in this shell.'
Using grails version 2.4.5 in this shell.
+ [[ use != \s\e\l\f\u\p\d\a\t\e ]]
+ __sdkman_auto_update 5.5.4+199 5.1.18+191
+ local remote_version version delay_upgrade
+ remote_version=5.5.4+199
+ version=5.1.18+191
+ delay_upgrade=/var/lib/jenkins/.sdkman/var/delay_upgrade
++ find /var/lib/jenkins/.sdkman/var/delay_upgrade -mtime +1
+ [[ -n /var/lib/jenkins/.sdkman/var/delay_upgrade ]]
+ [[ 5.5.4+199 != \5\.\1\.\1\8\+\1\9\1 ]]
+ echo ''

+ echo ''

+ __sdkman_echo_yellow 'ATTENTION: A new version of SDKMAN is available...'
+ __sdkman_echo 33m 'ATTENTION: A new version of SDKMAN is available...'
+ [[ false == \f\a\l\s\e ]]
+ echo -e 'ATTENTION: A new version of SDKMAN is available...'
ATTENTION: A new version of SDKMAN is available...
+ echo ''

+ __sdkman_echo_no_colour 'The current version is 5.5.4+199, but you have 5.1.18+191.'
+ echo 'The current version is 5.5.4+199, but you have 5.1.18+191.'
The current version is 5.5.4+199, but you have 5.1.18+191.
+ echo ''

+ [[ false != \t\r\u\e ]]
+ __sdkman_echo_confirm 'Would you like to upgrade now? (Y/n)'
+ [[ false == \f\a\l\s\e ]]
+ echo -n 'Would you like to upgrade now? (Y/n)'
Would you like to upgrade now? (Y/n)+ read upgrade
Build step 'Execute shell' marked build as failure

What's also interesting is that checking version on the server shows the 5.5.4+199 but checking via jenkins bash script 5.1.18+191 ?

I'm using a login shell to spawn a new bash script.

#!/bin/bash -elx
sdk u groovy 2.4.8
groovy script.groovy

Ubuntu 14.04.3 LTS GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) Jenkins 2.21 sdkman 5.5.4+199 - showing on the cmd right now

marc0der commented 7 years ago

I think the login shell might be your problem. Would it be possible to source the sdkman_init.sh some other way?

moziauddin commented 6 years ago

You can use the below... echo "sdkman_auto_answer=true" > ~/.sdkman/etc/config