Skip to content

How to set _authToken via pnpmCommand? #303

Open

Description

@antpaw

I'm looking for a way to do something like this. Does anyone know how I could set the token? I do not want to set it via project's .npmrc. Thank you!

  pnpmCommand.set(listOf("config set https://npm.pkg.github.com/:_authToken $authToken"))

Activity

  1. deepy commented on Feb 13, 2024

    @deepy
    Member

    Based on the constraints I'd recommend using an environment variable
    https://pnpm.io/npmrc#url_authtoken
    pnpm/pnpm#3141 (comment)

  2. antpaw commented on Feb 13, 2024

    @antpaw
    Author

    Thanks you for your reply!

    i've tried two things, setting it the env with gradle.

    val buildFrontend by tasks.registering(PnpmTask::class) {
        val version = project.property("version")
        environment.set(
            mapOf(
                "VITE_MY_VERSION" to version.toString(),
                "npm_config_//npm.pkg.github.com/:_authtoken" to authToken.toString()
            )
        )
        pnpmCommand.set(listOf("build:web"))
        dependsOn(tasks.pnpmInstall)
    

    it still errors out on install with 401

    > Task :frontend:pnpmInstall
    Progress: resolved 0, reused 1, downloaded 0, added 0
     ERR_PNPM_FETCH_401  GET https://npm.pkg.github.com/some-pkg: Unauthorized - 401
    

    and setting it directly in bash

    $ export npm_config_//npm.pkg.github.com/:_authtoken=myToken            
    export: not valid in this context: npm_config_//npm.pkg.github.com/:_authtoken
    

    this errors out with not valid because of all the special chars like . and / right?

    It looks like that the env example is only working for github actions? I'm running this on jenkins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions