firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.21k stars 125 forks source link

a local variable cannot be accessed #1074

Closed danielzzz closed 8 months ago

danielzzz commented 8 months ago

Hello, I am having this strange problem:

I am using a multiline local variable, which is a base64 encoded keystore for android:

STORE_PASSWORD: "1234"
KEY_ALIAS: key
KEY_PASSWORD: "1234"
KEYSTORE: |
  /u3+7QAAAAIAAAABAAAAAQADa2V5AAABUc51cjEAAAUDMIIE/zAOBgorBgEEASoCEQEBBQAEggTr
  HwKjYqy9zlglEirKbkOEF8hnmQbUwS1j0X+1eiEd6sudeasZGOeOzCQ/mPQT/aleCxOtendSbJqp
  l+yKROV+L7ANGCxzauC0qSPd5W1XnjU30hOov0uYKfb6Kk7XY7irVJ/qPCdT3Hh0fc2idMXsFhJl
  ...rest of the code

the problems:

  1. it seems to be stored as a file not as a variable
    echo $KEYSTORE:
    /tmp/gitlab-ci-local-file-variables-daniel-618744/KEYSTORE
  2. but when I try to cat it I am getting an error:
    
    build $ cat ${KEYSTORE}
    build > warn: KEYSTORE is pointing to invalid path
**Minimal .gitlab-ci.yml illustrating the issue**
```yml
---
build:
  script:
    - echo ${KEYSTORE}
    - cat ${KEYSTORE}

Expected behavior I would expect KEYSTORE to be an env variable in this case and I would like to be able to actually read it.

Host information Ubuntu gitlab-ci-local 4.46.0

firecow commented 8 months ago

This is due to a "not-so-smart" file detection we implemented. It's scheduled to be removed in the next major version https://github.com/firecow/gitlab-ci-local/discussions/335#discussion-3724247

Use the more explicit variable declaration style see this

global:
  KEYSTORE:
    type: variable
    values:
      '*': |
        /u3+7QAAAAIAAAABAAAAAQADa2V5AAABUc51cjEAAAUDMIIE/zAOBgorBgEEASoCEQEBBQAEggTr
        HwKjYqy9zlglEirKbkOEF8hnmQbUwS1j0X+1eiEd6sudeasZGOeOzCQ/mPQT/aleCxOtendSbJqp
        l+yKROV+L7ANGCxzauC0qSPd5W1XnjU30hOov0uYKfb6Kk7XY7irVJ/qPCdT3Hh0fc2idMXsFhJl
        ...rest of the code
danielzzz commented 8 months ago

is it possible to use this syntax in gitlab-ci-local-variables.yml ? or just in .gitlab-ci-local/variables.yml

this syntax is giving me an error in the former

image

firecow commented 8 months ago

What have you tried so far?

danielzzz commented 8 months ago

basically, I copied your code to the file, both with and without the "global" section. but neither worked..

danielzzz commented 8 months ago

it did work when I copied the file to the project .gitlab-ci-local directory as variables.yml but I would rather avoid using it this way, as often I have to delete this dir due to conflicts with the locally executed code

firecow commented 8 months ago

Show me exactly what your are doing šŸ¤£ I'm not following

danielzzz commented 7 months ago

ok, I have a repository, with a .gitlab-local.ci.yml file it's an android app and I want to use a base64 encoded keystore as a variable

but when I use it like this:

KEYSTORE: |
  /u3+7QAAAAIAAAABAAAAAQADa2V5AAABUc51cjEAAAUDMIIE/zAOBgorBgEEASoCEQEBBQAEggTr
  HwKjYqy9zlglEirKbkOEF8hnmQbUwS1j0X+1eiEd6sudeasZGOeOzCQ/mPQT/aleCxOtendSbJqp
  l+yKROV+L7ANGCxzauC0qSPd5W1XnjU30hOov0uYKfb6Kk7XY7irVJ/qPCdT3Hh0fc2idMXsFhJl
  ...rest of the code

it's not working. it returns a file path, but then the file cannot be read.

  1. your suggestion to use this format:
    
    global:
    KEYSTORE:
    type: variable
    values:
      '*': |

did not work... it's giving this error:
![image](https://github.com/firecow/gitlab-ci-local/assets/351916/cf87e3cc-89b3-45dd-96eb-44d15478a296)

3. the only way it worked was when I copied it to the .gitlab-local-ci directory that is created by gcl and put it in the variables.yml file

4. but this does not work for me, because I have to delete this .gitlab-local-ci dir often as it conflicts with some other scripts. for example yarn/gradle detects all the code inside it and complains about duplicates when I run it locally without gcl     

so my question is, how / if could I use this extended format you sent in the normal .gitlab-local-ci.yml file, please?

I hope I could explain myself. thanks in advance for your help!
firecow commented 7 months ago
global:
KEYSTORE:
  type: variable
  values:
    '*': |

Isn't what i postef.

Identation is important in ~/.gitlab-ci-local/variables.yml

global:
  KEYSTORE:

You can use the HOME variables or the PROJECT variables to solve your problems.

https://github.com/firecow/gitlab-ci-local?tab=readme-ov-file#home-file-variables

https://github.com/firecow/gitlab-ci-local?tab=readme-ov-file#project-file-variables

danielzzz commented 7 months ago

sorry, that's true. I pasted it not correctly.

but I want to use it in a project file, and it seems this format is not working there. I mean with the "global" keyword or using the KEYSTORE variable directly with type and value keys.

would you please kindly confirm that or is it possible to use type/value also in proyect file vars?

firecow commented 7 months ago

Where do you place you .gitlab-ci-local-variables.yml file exactly ? It needs to be placed in your projects root, right next to .gitlab-ci.yml

KEYSTORE:
  type: variable
  values:
    '*': |
danielzzz commented 7 months ago

sorry and thank you for you patience, it was a formatting problem on my side. fixed.