# Travis-ci.org - Octokit::Unauthorized prevents release to Github

**URL:** https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113
**Category:** Deployment
**Tags:** github-releases
**Created:** [April 12, 2020, 10:05am UTC](https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113 "2020-04-12T10:05:48Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![dotherightthing](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/dotherightthing/32/2871_2.png) [@dotherightthing](https://travis-ci.community/u/dotherightthing)
#### Post date: [April 12, 2020, 10:05am UTC](https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113/1 "2020-04-12T10:05:48Z")

</div>

My Github projects use Travis CI to compile front end files and generate a release.zip for upload back to Github.

After some months away from these projects, this release deployment process is no longer working.

E.g. [https://travis-ci.org/github/dotherightthing/gulp-wpdtrt-plugin-bump/builds/674013205](https://travis-ci.org/github/dotherightthing/gulp-wpdtrt-plugin-bump/builds/674013205)

I have searched around the web and through this forum, and have tried the following:

- validating my build config at [https://config.travis-ci.com/explore](https://config.travis-ci.com/explore)
- generating a new Github Personal Access Token and recreating the Travis environmental variable
- as above, plus encrypting this using `travis encrypt my_github_api_personal_access_token`
- confirming that I can connect to the Github API using this token unencrypted, using `curl -H "Authorization: token my_github_api_personal_access_token" https://api.github.com`
- using the encrypted token in my Travis build config rather than the environmental variable
- renaming my environmental variable from `$GH_TOKEN` to `$GITHUB_TOKEN` and removing the token key, as per my understanding of [https://docs.travis-ci.com/user/deployment-v2/providers/releases/](https://docs.travis-ci.com/user/deployment-v2/providers/releases/) (this failed)
- using `token.secure` with quoted `"$GITHUB_TOKEN"` and unquoted `$GITHUB_TOKEN` values
- confirming that I am still using [travis-ci.org](http://travis-ci.org) (public projects) and not the new [travis-ci.com](http://travis-ci.com) (public/private projects, in beta)
- confirming that I am not using GitHub Enterprise

---

<div class="post-metadata">

### Author: ![hasufell](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/hasufell/32/4306_2.png) [@hasufell](https://travis-ci.community/u/hasufell)
#### Post date: [April 12, 2020, 10:37am UTC](https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113/2 "2020-04-12T10:37:51Z")

</div>

Same here:

1. failure: [https://travis-ci.com/github/hasufell/ghcup-hs/jobs/318551270#L1888](https://travis-ci.com/github/hasufell/ghcup-hs/jobs/318551270#L1888)
2. the commit after which the failure occured: [https://github.com/hasufell/ghcup-hs/commit/b11b74d2b48834fa9a69cde9c2b5f503b1be07a8](https://github.com/hasufell/ghcup-hs/commit/b11b74d2b48834fa9a69cde9c2b5f503b1be07a8)

As can bee seen, the commit has nothing to do with travis config. No credentials were touched. The credentials were generated with ‘travis setup release’ a day before.

---

<div class="post-metadata">

### Author: ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)
#### Post date: [April 12, 2020, 10:33pm UTC](https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113/3 "2020-04-12T22:33:48Z")

</div>

> **[Travis CI - Test and Deploy with Confidence](https://app.travis-ci.com/github/dotherightthing/gulp-wpdtrt-plugin-bump/jobs/674013206/config)**
>
> Travis CI enables your team to test and ship your apps with confidence. Easily sync your projects with Travis CI and you'll be testing your code in minutes.

This is invalid syntax:

```auto
deploy:
  <...>
  token:
    secure: $GITHUB_TOKEN

```

It should be just

```auto
deploy:
  <...>
  token: $GITHUB_TOKEN

```

if the value is in an envvar.

* * *

[https://config.travis-ci.com/explore](https://config.travis-ci.com/explore) actually warns you of this:

> ### Parsed and validated config
> 
> [warn] on deploy.token.secure: invalid value on secure string: {:secure=\>“$GITHUB\_TOKEN”}

---

<div class="post-metadata">

### Author: ![dotherightthing](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/dotherightthing/32/2871_2.png) [@dotherightthing](https://travis-ci.community/u/dotherightthing)
#### Post date: [April 13, 2020, 12:13am UTC](https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113/4 "2020-04-13T00:13:04Z")

</div>

Ah, apologies. I used to use this:

```auto
deploy:
  api_key:
    secure: $GH_TOKEN

```

… but rewrote this following feedback from the validator.

I didn’t understand what the remaining error was telling me - I just thought that it couldn’t resolve the dynamic envvar.

Anyway, I updated the Travis build config but it is still failing despite being valid:

[https://travis-ci.org/github/dotherightthing/gulp-wpdtrt-plugin-bump/builds/674211404](https://travis-ci.org/github/dotherightthing/gulp-wpdtrt-plugin-bump/builds/674211404)

---

<div class="post-metadata">

### Author: ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)
#### Post date: [April 13, 2020, 1:31am UTC](https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113/5 "2020-04-13T01:31:42Z")

</div>

Comparing the stacktrace with [https://github.com/travis-ci/dpl/blob/v1.10.15/lib/dpl/provider/releases.rb](https://github.com/travis-ci/dpl/blob/v1.10.15/lib/dpl/provider/releases.rb), the error happens at checking credentials.  
If you are sure your token is correct, maybe [it doesn’t have required permissions](https://docs.travis-ci.com/user/deployment/releases/#authenticating-with-an-oauth-token)?

FYI, [you are not using deployment v2](https://docs.travis-ci.com/user/deployment-v2#how-to-opt-in-to-v2), so refer to [https://docs.travis-ci.com/user/deployment/releases/](https://docs.travis-ci.com/user/deployment/releases/).

* * *

You can also double-check if your token is decrypted correctly by printing a small part of it.

---

<div class="post-metadata">

### Author: ![dotherightthing](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/dotherightthing/32/2871_2.png) [@dotherightthing](https://travis-ci.community/u/dotherightthing)
#### Post date: [April 13, 2020, 9:46am UTC](https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113/7 "2020-04-13T09:46:56Z")

</div>

> [@native-api](#):
>
> You can also double-check if your token is decrypted correctly by printing a small part of it.

Thanks, how would I go about doing this?

---

<div class="post-metadata">

### Author: ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)
#### Post date: [April 13, 2020, 10:40am UTC](https://travis-ci.community/t/travis-ci-org-octokit-unauthorized-prevents-release-to-github/8113/8 "2020-04-13T10:40:23Z")

</div>

> <https://stackoverflow.com/questions/428109/extract-substring-in-bash/428580#428580>
