Unable to run gpg on circleci - "Required environment variable not set" error

Update: I wasn’t executing gpg properly. It worked with
gpg --batch --generate-key foo

I am trying to generate keys with gpg and keep running into the error below. Could you please tell me what I need to do? This works on my Mac as well as on other Cloud VMs. I am having this issue only on circleci.

What i am doing: I am invoking a shell script during my run step which does the following:

#!/bin/bash

echo “STARTING GPG STUFF…”
ATTESTOR_EMAIL="myemail@gmail.com"

gpg --quick-generate-key --yes ${ATTESTOR_EMAIL}

gpg --armor --export “${ATTESTOR_EMAIL}” > generated-key.pgp

I keep getting the following error “gpg: agent_genkey failed: Required environment variable not set”

Output:

STARTING GPG STUFF…
gpg: directory ‘/root/.gnupg’ created
gpg: keybox ‘/root/.gnupg/pubring.kbx’ created
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: agent_genkey failed: Required environment variable not set
Key generation failed: Required environment variable not set
gpg: WARNING: nothing exported

(Posted a solution on behalf of the question author).

I wasn’t executing gpg properly. It worked with gpg --batch --generate-key foo.

@nmallya: if you find an answer yourself, please add a new post, so you can use the “solved” button. You can mark my post above as the solution if you wish, or post it again, and I will delete my copy.

This way, the original question survives, and has a clearly marked answer below. This may be useful for future readers with the same problem.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.