Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 2
Message 1 of 5

Github Actions Python subprocess.run

Solved! Go to Solution.

Hello,
I have a python file which I'd like to use as part of a Github Action. It uses subprocess.run(). For some reason, this fails in a Github Action.

Here is the code in question, where "arg_method" is the string "decrypt":

for file in files_to_handle:
process = subprocess.run(
[
"gcloud",
"kms",
arg_method,
"--location=" + hidden,
"--keyring=" + hidden,
"--key=" + hidden,
"--plaintext-file=" + hidden,
"--ciphertext-file=" + hidden
],
shell=True,
check=True
)


The github action always fails on this step. Here is the output:

Run python python_script_name_hidden.py --method=decrypt --env=production --yes
ERROR: (gcloud) Command name argument expected.


It appears the arguments are not being passed to the subprocess. It is not getting as far as "kms"

Any advice on how to fix this?

Thank you.

4 Replies
Highlighted
Solution
Ground Controller Lvl 2
Message 2 of 5

Re: Github Actions Python subprocess.run

Hey all. I solved this. Running this on a Linux server revealed it wasn't working everywhere.

I changed the script to the following, which seems to have worked:

for file in files_to_handle:
    process = subprocess.Popen(
        [
            "gcloud",
            "kms",
            arg_method,
            "--location=" + hidden,
            "--keyring=" + hidden,
            "--key=" + hidden,
            "--plaintext-file=" + hidden,
            "--ciphertext-file=" + hidden
        ],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE
    )

    output, error = process.communicate()

    if process.returncode != 0:
        raise Exception("File handling failed %d %s %s" % (process.returncode, output, error))

 
I thought I'd update this incase anyone has a similar issue

Highlighted
GitHub Partner
Message 3 of 5

Re: Github Actions Python subprocess.run

@codebykyle ,

Glad to hear that the problem has been solved. And thanks for sharing your experiences.

Highlighted
Ground Controller Lvl 2
Message 4 of 5

Re: Github Actions Python subprocess.run

Hey @BrightRan 

Thanks for the quick reply. I ran this on another machine and was able to replicate the issue. I solved this by using subprocess.Popen as opposed to subprocess.run.

Thanks for the suggestions. I marked the previous reply as a solution to avoid any confusion.

Thanks,

-Kyle

Highlighted
GitHub Partner
Message 5 of 5

Re: Github Actions Python subprocess.run

@codebykyle ,

Yeah, I didn't noticed your previous reply until I submitted my reply, so I changed my reply.
Anyway, thanks again for share your experiences here. I believe this can help more people who have the same/similar problems.