2

I want to make an updater for my Electron application, and I stuck on the GitHub access token.

I have generated a token from my GitHub account, and after that, I tried to set that token in my Windows environmental variables.

When I go to my application and I run this file publish.sh

publish.sh

#!/bin/sh

if [ -z "$GH_TOKEN" ]; then
    echo "You must set the GH_TOKEN environment variable."
    echo "See README.md for more details."
    exit 1
fi

# This will build, package and upload the app to GitHub.
node_modules/.bin/build --win --mac -p always

I run this file ./publish.sh and I get this message:

You must set the GH_TOKEN environment variable.

I want to achieve step 4 and 5 in this example: https://github.com/iffy/electron-updater-example

I tried to run this command from the Git Bash export GH_TOKEN="435468246872235283762846848267", but I get a return code of 0.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
George C.
  • 6,574
  • 12
  • 55
  • 80

1 Answers1

2

How do I set an environment variable on Windows 10, which was generated from GitHub?

Make sure to restart a new CMD session (in which you can type bash) in order to make sure your session does inherit the new Windows environment variable you have just set.

Once you have done that, you can check in the (new) Git Bash session which are the environment variables already set, with:

env
env | grep GH

Make sure your script starts with

#!/bin/bash

The OP George points out in the comments that the correct form is:

export GH_TOKEN=MY_VARIABLE_NAME

(no double quotes)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • C:\Users\George\Desktop>git bash git: 'bash' is not a git command. See 'git --help'. Did you mean this? stash C:\Users\George\Desktop> I type git bash inside gitbash and is say no such command the same inside cmd were i type this command ??? – George C. Mar 12 '17 at 22:57
  • i type env and i find my variable – George C. Mar 12 '17 at 23:01
  • Then simply type bash – VonC Mar 13 '17 at 05:01
  • If you see your variable, then your script should work (although I recommend stating it with `#!/bin/bash`) – VonC Mar 13 '17 at 05:25
  • i make a big mistake i type GH_TOKEN="52462676/4762762587425" and the right way was GH_TOKEN=MY_VARIABLE_NAME no "" no numbers only the varible name that i create when i set it on windows variables :) but thnx bro for your help – George C. Mar 13 '17 at 05:30
  • @George Right! I have included that in the answer for more visibillity – VonC Mar 13 '17 at 05:32
  • OMG i dont refresh the page and i dont see that answer lol now i see that – George C. Mar 13 '17 at 05:33