how to run nvm on a linux agent

966 views
Skip to first unread message

steinber...@outlook.com

unread,
Jul 6, 2015, 1:01:27 PM7/6/15
to go...@googlegroups.com
I have been digging around for the last few days, and tried various ways of adding nvm to the go user's path, but i still cannot get access to nvm.  I was able to get into the version of node that nvm installed.

here is the relevant debug output

Error happened while attempting to execute '/var/go/.nvm/nvm current'. 
Please make sure [/var/go/.nvm/nvm] can be executed on this agent.

[Debug Information] Environment variable PATH: /var/go/.nvm:/var/go/.nvm/v0.10.36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Ketan Padegaonkar

unread,
Jul 6, 2015, 1:45:44 PM7/6/15
to go...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

steinber...@outlook.com

unread,
Jul 6, 2015, 1:55:25 PM7/6/15
to go...@googlegroups.com
Is wrapping the call in a shell script really the only way?

Aravind SV

unread,
Jul 6, 2015, 2:16:58 PM7/6/15
to go...@googlegroups.com
Is /var/go/.nvm/nvm executable (meaning, has chmod +x been done on it)? Are there any other logs on the agent?

steinber...@outlook.com

unread,
Jul 6, 2015, 3:27:22 PM7/6/15
to go...@googlegroups.com
the default installation does not set nvm.sh as executable. 

2015-07-06 18:26:35,211 [loopThread] INFO  go.util.command.CommandLine:455 - Running command: nvm current

2015-07-06 18:26:35,241 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_SERVER_URL' to value 'https://mygoserver:8154/go/'
2015-07-06 18:26:35,241 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_TRIGGER_USER' to value 'me'
2015-07-06 18:26:35,241 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_PIPELINE_NAME' to value 'node-linux-experiment'
2015-07-06 18:26:35,242 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_PIPELINE_COUNTER' to value '1'
2015-07-06 18:26:35,242 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_PIPELINE_LABEL' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
2015-07-06 18:26:35,243 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_STAGE_NAME' to value 'defaultStage'
2015-07-06 18:26:35,243 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_STAGE_COUNTER' to value '32'
2015-07-06 18:26:35,243 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_JOB_NAME' to value 'defaultJob'
2015-07-06 18:26:35,244 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
2015-07-06 18:26:35,244 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_TO_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
2015-07-06 18:26:35,244 [loopThread] INFO  go.util.command.CommandLine:62 - [go] setting environment variable 'GO_FROM_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
2015-07-06 18:26:35,256 [loopThread] ERROR thoughtworks.go.util.ProcessManager:104 - [Command Line] Failed executing [nvm current]
2015-07-06 18:26:35,257 [loopThread] ERROR thoughtworks.go.util.ProcessManager:105 - [Command Line] Agent's Environment Variables: {TERM=xterm, JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre, SHLVL=2, LOG_DIR=/var/log/go-agent,  MAIL=/var/mail/go, LOG_FILE=/var/log/go-agent/go-agent-bootstrapper.log, GO_SERVER=mygoserver,  PWD=/var/lib/go-agent, LOGNAME=go, AGENT_WORK_DIR=/var/lib/go-agent, _=/usr/bin/nohup, OLDPWD=/var/go, SHELL=/bin/bash, AGENT_STARTUP_ARGS=-Dcruise.console.publish.interval=10 -Xms128m -Xmx256m   , PATH=/var/go/.nvm:/var/go/.nvm/v0.10.36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games, USER=go,  GO_SERVER_PORT=8153, HOME=/var/go, XDG_SESSION_ID=2, XDG_RUNTIME_DIR=/run/user/1000, LANG=en_US.UTF-8}
2015-07-06 18:26:35,260 [loopThread] WARN  go.util.command.CommandLine:62 - Error happened while attempting to execute 'nvm current'.
Please make sure [nvm] can be executed on this agent.

2015-07-06 18:26:35,260 [loopThread] WARN  go.util.command.CommandLine:62 - [Debug Information] Environment variable PATH: /var/go/.nvm:/var/go/.nvm/v0.10.36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
2015-07-06 18:26:35,261 [loopThread] ERROR go.util.command.CommandLine:477 - [Command Line] Error happened while attempting to execute 'nvm current'.
Please make sure [nvm] can be executed on this agent.
. Path: /var/go/.nvm:/var/go/.nvm/v0.10.36/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
2015-07-06 18:26:35,269 [loopThread] WARN  go.domain.builder.BaseCommandBuilder:104 - exec error
2015-07-06 18:26:35,269 [loopThread] WARN  go.domain.builder.BaseCommandBuilder:99 - Could not execute command: nvm current

Aravind SV

unread,
Jul 6, 2015, 4:48:48 PM7/6/15
to go...@googlegroups.com
On Mon, Jul 6, 2015 at 3:27 PM, <steinber...@outlook.com> wrote:
the default installation does not set nvm.sh as executable. 

It looks like nvm is a shell function, and not an executable file. That's probably what is happening. In that case, what Ketan said will work, since that sources nvm, before executing it.

You'll probably see the same behavior as in Go, when you do this:

$ /bin/bash -c nvm
/bin/bash: nvm: command not found

Again, this is because nvm is not sourced, in that new shell. That's essentially what Go Agent will do too, when executing any task. If you really don't want to do what Ketan said, you can consider changing the bash initialization scripts to make sure that the nvm.sh file is sourced. You can read about bash's initialization here (look for the text "When bash is started non-interactively" in that page).

Finally, there's not much Go can do about this (this is not something that needs fixing), because that is how bash works, and nvm has decided to use a shell feature, rather than proper executables (same as rbenv vs rvm). So, I'd use a wrapper like the one Ketan provided, and check that into a tools/ directory, so that the build can use it.

Cheers,
Aravind

steinber...@outlook.com

unread,
Jul 6, 2015, 8:54:39 PM7/6/15
to go...@googlegroups.com
I have attempted to use the shell script method
https://gist.github.com/lostrouter/695fb94cf7510fae77c9

I have tried a few different arrangements of the arguments in go, and still wind up with problems

I have set BASH_ENV at the job level environment variable to point to /var/go/set-node-version.sh

[go] Start to execute task: <exec command="/bin/bash" >
<arg>-c</arg>
<arg>SetNodeVersion</arg>
<arg>0.10.36</arg>
</exec>. 
[go] setting environment variable 'GO_ENVIRONMENT_NAME' to value 'FOO'
[go] setting environment variable 'GO_SERVER_URL' to value 'https://mygoserver:8154/go/'
[go] setting environment variable 'GO_TRIGGER_USER' to value 'x4ex'
[go] setting environment variable 'GO_PIPELINE_NAME' to value 'node-linux-experiment'
[go] setting environment variable 'GO_PIPELINE_COUNTER' to value '1'
[go] setting environment variable 'GO_PIPELINE_LABEL' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
[go] setting environment variable 'GO_STAGE_NAME' to value 'defaultStage'
[go] setting environment variable 'GO_STAGE_COUNTER' to value '62'
[go] setting environment variable 'GO_JOB_NAME' to value 'defaultJob'
[go] setting environment variable 'GO_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
[go] setting environment variable 'GO_TO_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
[go] setting environment variable 'GO_FROM_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
[go] setting environment variable 'BASH_ENV' to value '/var/go/set-node-version.sh'
incorrect usage
Usage:
  SetNodeVersion <VERSION>

[go] Start to execute task: <exec command="/bin/bash" >
<arg>-c</arg>
<arg>"SetNodeVersion 0.10.36"</arg>
</exec>. 
[go] setting environment variable 'GO_ENVIRONMENT_NAME' to value 'FOO'
[go] setting environment variable 'GO_SERVER_URL' to value 'https://mygoserver:8154/go/'
[go] setting environment variable 'GO_TRIGGER_USER' to value 'x4ex'
[go] setting environment variable 'GO_PIPELINE_NAME' to value 'node-linux-experiment'
[go] setting environment variable 'GO_PIPELINE_COUNTER' to value '1'
[go] setting environment variable 'GO_PIPELINE_LABEL' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
[go] setting environment variable 'GO_STAGE_NAME' to value 'defaultStage'
[go] setting environment variable 'GO_STAGE_COUNTER' to value '62'
[go] setting environment variable 'GO_JOB_NAME' to value 'defaultJob'
[go] setting environment variable 'GO_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
[go] setting environment variable 'GO_TO_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
[go] setting environment variable 'GO_FROM_REVISION_CHANGESET' to value '4a5baab14a755eec3c5e397f015e973230ddfe3e'
[go] setting environment variable 'BASH_ENV' to value '/var/go/set-node-version.sh'
/bin/bash: SetNodeVersion 0.10.36: command not found

why can't i pass a parameter to my function?

Ketan Padegaonkar

unread,
Jul 6, 2015, 9:07:17 PM7/6/15
to go...@googlegroups.com

Can you show me what goes into  /var/go/set-node-version.sh?


--

Michael Steinberg

unread,
Jul 6, 2015, 9:16:29 PM7/6/15
to go...@googlegroups.com
See my link to my gist

--M

From: Ketan Padegaonkar
Sent: ‎7/‎6/‎2015 6:07 PM
To: go...@googlegroups.com
Subject: Re: [go-cd] how to run nvm on a linux agent

You received this message because you are subscribed to a topic in the Google Groups "go-cd" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/go-cd/_1MnoXNGT78/unsubscribe.
To unsubscribe from this group and all its topics, send an email to go-cd+un...@googlegroups.com.

Ketan Padegaonkar

unread,
Jul 6, 2015, 11:14:37 PM7/6/15
to go...@googlegroups.com
Quoting in bash to make it a single argument, is equivalent to wrapping it in <arg/>. Your second variant is close to what you'd want to use, except for the additional quotes that need to be removed. This works for me -

  <exec command="/bin/bash">
    <arg>-c</arg>
    <arg>SetNodeVersion 0.12.3</arg>
  </exec>

If you already have your bash profile setup correctly, you may try setting BASH_ENV to $HOME/.profile or whatever your profile to get the goodness of other shell functions like rbenv or rvm.

--

steinber...@outlook.com

unread,
Jul 7, 2015, 12:36:45 PM7/7/15
to go...@googlegroups.com
that was it. thank you.

steinber...@outlook.com

unread,
Jul 10, 2015, 8:23:24 PM7/10/15
to go...@googlegroups.com
I have a new problem that is related to this.  I spun up a new agent.  after the script finishes, now it cannot find node or npm.  however from within the script it can find node and npm.  anythoughts on what is happening to the go user's path and why it isn't getting set properly by nvm?
Reply all
Reply to author
Forward
0 new messages