PATH not honoured

33 views
Skip to first unread message

Pablo León

unread,
Jul 8, 2024, 8:53:41 AMJul 8
to go-cd
Hi,

I have configured a PATH environment variable in my pipeline,
I see an "overriding environment variable 'PATH' with value '/usr/lib/jvm/java-11-openjdk:/usr/bin'" line in the logs, I even can see the new value of PATH in an "printenv" task.

However, this value doesn't seems to be honoured as a search path!

What is the recommend way to change the search path in go-cd?

I know I can change this in the /usr/share/go-agent/wrapper-config/wrapper-properties.conf file, but what if I need a different paths for each job? (for example for different java versions)

Cheers!

Jason Smyth

unread,
Jul 8, 2024, 11:13:14 AMJul 8
to go-cd
Hi Pablo,

Why do you feel that the PATH variable is not being honoured? You provide two examples of details that suggest that it _should_ be working, but assert that is not. What behaviour are you seeing that gives you that impression?

With that said, I'm not sure that overriding the PATH is the best way to accomplish your objective. I think using the Java-specific variables like JAVA_HOME would be a cleaner way to handle your example case of multiple Java versions.

I'm struggling to imagine a scenario where completely overriding the PATH isn't more trouble than its worth, though of course that doesn't mean that such a use case doesn't exist.

Hope this helps.

Cheers,
Jason Smyth

Pablo León

unread,
Jul 8, 2024, 12:39:45 PMJul 8
to go-cd
Hi Jason:

For testing purposes I have created a single job pipeline:

Captura de pantalla 2024-07-08 174021.png
with this single environment variable:
Captura de pantalla 2024-07-08 174219.png

and this is the log I get when I run the pipeline:
Captura de pantalla 2024-07-08 174302.png

which shows an interesting [Debug information] ...

If I change the path in  /usr/share/go-agent/wrapper-config/wrapper-properties.conf, then the pipeline runs fine.

With respect to changing JAVA_HOME environment variable, I can't make this work without changing the PATH ...

    [pablo.leon@devel ~]$ export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
    [pablo.leon@devel ~]$ java -version
    openjdk version "21.0.3" 2024-04-16 LTS

Chad Wilson

unread,
Jul 8, 2024, 1:07:27 PMJul 8
to go...@googlegroups.com
That won't work because tasks you launch like this are being launched directly, forked from the GoCD agent process. When you do this you're setting the env vars for all processes that are launched from this process, but not changing the agent process env itself. If this were allowed, it'd create chaos as an agent can run many jobs.

So it is setting the PATH for the launch environment of the flutter process itself, but that process would have to actually launch which is too late.

If you want to change the PATH like that youd need to do so via an intermediary shell (sh -c 'flutter doctor') or use a shell script for all of your steps. That way the path is passed into the shell and then used to find things.

But personally I think there are probably better and less coupled ways to manage versions for dev tools than the path that, e.g tools like sdkman or mise where your agent could have pre-installed versions and consuming jobs can use a version controlled config that defines the required versions and then locates them dynamically (using shims or wrapping launchers).

-Chad

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/go-cd/5228fbee-b5db-41c9-b0ad-92d8daa2116dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages