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

**URL:** <https://discuss.circleci.com/t/unable-to-run-gpg-on-circleci-required-environment-variable-not-set-error/27207>\
**Category:** Build Environment\
**Tags:** circle-yml\
**Created:** [December 18, 2018, 5:13am UTC](https://discuss.circleci.com/t/unable-to-run-gpg-on-circleci-required-environment-variable-not-set-error/27207 "2018-12-18T05:13:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmallya](https://avatars.discourse-cdn.com/v4/letter/n/cc9497/32.png) [@nmallya](https://discuss.circleci.com/u/nmallya)\
**Post date:** [December 18, 2018, 5:13am UTC](https://discuss.circleci.com/t/unable-to-run-gpg-on-circleci-required-environment-variable-not-set-error/27207/1 "2018-12-18T05:13:47Z")

</div>

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](mailto:ATTESTOR_EMAIL=%22myemail@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

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [February 23, 2019, 1:13pm UTC](https://discuss.circleci.com/t/unable-to-run-gpg-on-circleci-required-environment-variable-not-set-error/27207/3 "2019-02-23T13:13:54Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [February 23, 2019, 1:15pm UTC](https://discuss.circleci.com/t/unable-to-run-gpg-on-circleci-required-environment-variable-not-set-error/27207/4 "2019-02-23T13:15:58Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [March 5, 2019, 1:16pm UTC](https://discuss.circleci.com/t/unable-to-run-gpg-on-circleci-required-environment-variable-not-set-error/27207/5 "2019-03-05T13:16:02Z")

</div>

Closed on March 5, 2019, 1:16pm UTC

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