Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running sourced script functions does not work #3

Open
frwickst opened this issue Feb 24, 2021 · 3 comments
Open

Running sourced script functions does not work #3

frwickst opened this issue Feb 24, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@frwickst
Copy link

frwickst commented Feb 24, 2021

Say that you have the following file, scripts.sh with:

hello_world() {
    echo "Hello world!"
}

If I in the pipeline would be to do the following in my script or in my case before_script:

- source scripts.sh
- hello_word

Then I would expect "Hello world" to be echoed.

This is something that works as expected when running in a normal GitLab CI Runner, however in the case of glci I'm getting this:

sh: hello_world: not found

I'm guessing the the problem here is that you do something different from that the GitLab runner is doing. As it says sh here and not bash I do see why this is not working however. And you are running sh here it seems

Cmd: ["sh", "-c", command],

So this is something that GitLab clearly does differently than glci.

@richard-melvin
Copy link

Example has function say_hello and call hello_world; does it still not work if they match?

@frwickst
Copy link
Author

frwickst commented Feb 25, 2021

Ah, that was just an example I wrote. I'll fix it to have the correct name in both places. This was not the actual code I'm running, which does work as expected on GitLabs on CI.

@mdubourg001
Copy link
Owner

I just tried out and this indeed does not work as expected.

The difference between GitLab CI and glci is that glci runs a docker exec inside the container for each command of the script keyword, while GitLab CI most probably (guessing here, not sure) maintain a single interactive shell in the running container and runs commands one by one through it. While the GitLab CI way allows keeping sourced functions in the shell between commands, the glci way loses sourced functions between each execs.

So it's not a trivial change to do for glci, but I will try to POC the GitLab CI approach for glci.

A (temporary) workaround for this is to use a one-liner:

- source scripts.sh && hello_world 

Thanks for reporting this, I'll keep this thread updated when possible.

@mdubourg001 mdubourg001 added the enhancement New feature or request label Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants