Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Solved][Question] Set and use an encrypted environment variable #1982

Closed
kittaakos opened this issue Nov 21, 2018 · 3 comments
Closed

[Solved][Question] Set and use an encrypted environment variable #1982

kittaakos opened this issue Nov 21, 2018 · 3 comments
Labels

Comments

@kittaakos
Copy link

kittaakos commented Nov 21, 2018

Is it possible to set and use an encrypted GH_TOKEN/GITHUB_TOKEN environment variable with a personal OAuth token for GH? It is fairly straightforward for Travis CI and AppVeyor too.

It would be used by, for instance, the electron-builder and also it is a nice to have for vscode-ripgrep to avoid Error: API rate limit exceeded.

If this is possible, can someone please share a link to a sample configuration?

I would like to achieve the followings:

  • check out another private GitHub repository as part of the pipeline build,
  • use a private NPM registry during my build and publish there (yarn publish --no-git-tag-version could help though), and
  • deploy a new electron release to GH.

Thank you!


Solution:

  1. Select your pipeline.
  2. Click on Edit.
    screen shot 2018-11-21 at 17 00 54
  3. Click on Variables.
    screen shot 2018-11-21 at 17 01 11
  4. Define your variable. Make sure it is not a plain text.
    screen shot 2018-11-21 at 17 01 40

azure-pipelines.yml:

pool:
  vmImage: 'Ubuntu 16.04'

steps:
- script: mkdir foo && cd foo && git init && git pull https://$GH_TOKEN@github.com/nameOrOrganization/repositoryName.git && ls -al
  displayName: 'Clone with a predefined GitHub OAuth token'
  env:
     GH_TOKEN: $(gh.token)
@TingluoHuang
Copy link
Contributor

@kittaakos kittaakos changed the title [Question] Set and use an encrypted environment variable [Solved][Question] Set and use an encrypted environment variable Nov 21, 2018
@kittaakos
Copy link
Author

It works 🎉 @TingluoHuang, thank you for the pointer.

I made several mistakes, but honestly, it is misleading that I must not use $(GH_TOKEN) but $GH_TOKEN in the script. See the second example here. I assume it is because I did not use $(variables.GH_TOKEN) format.

@TingluoHuang
Copy link
Contributor

you don't have to use that, the following should also work.

- script: mkdir foo && cd foo && git init && git pull https://$(gh.token)@github.com/nameOrOrganization/repositoryName.git && ls -al
  displayName: 'Clone with a predefined GitHub OAuth token'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants