LocalOps
LocalOps

Reputation: 21

Running one liner shell commands with interactive prompts or script in gitlab CI

I need deploy some static site to survey.sh service, by following one-liner that works pretty well on my localhost from console and as script as well.

printf '%s\n' [email protected] somePassword  | surge --project ./public --domain domain_aka_domain_any_name.surge.sh 

surge (npm package)- is interactive command that prompt for login/registering e-mail and then password.

So by using printf it was successfully passed 2 answers on prompts from surge command on my host. And it's output is here:

Welcome to surge! (surge.sh) Login (or create surge account) by entering email & password.

      email: [email protected]
   password: 

Running as [email protected] (Student)

    project: ./public
     domain: ciicicicdciqq.surge.sh
     upload: [====================] 100% eta: 0.0s (66 files, 1699903 bytes)
        CDN: [====================] 100%
 encryption: *.surge.sh, surge.sh (366 days)
         IP: 138.197.235.000

Success! - Published to ciicicicdciqq.surge.sh

But when I use same one-liner or script.sh in .gitlab-ci.yml, on stage deploy like this:

deploy to surge:
  image: node
  stage: deploy
  script:
    - npm install --global surge
    - printf '%s\n' [email protected] somePassword  | surge --project ./public --domain domain_aka_domain_any_name.surge.sh

it didn't work, and it's output limited to:

Welcome to surge! (surge.sh) Login (or create surge account) by entering email & password. email: password: Cleaning up project directory and file based variables 00:01 Job succeeded

So, I assume that in docker container it's like interrupted on a second prompt (or may be even on first). Is it related to non-interactive shell or like that? I tried sh -c approach, but unlucky. Need help and reference on explanation/man. Thanks

EDIT, to clarify my question: What reason that Giitlab's/docker shell behavior different from my localhost and how to solve it by shell/unix way?. So, no matter it would be surge (I know about token possibility) command or anything else.

Upvotes: 0

Views: 912

Answers (1)

sytech
sytech

Reputation: 40861

Surge provides a token mechanism for authenticating from CI providers like GitLab and using surge non-interactively.

First, you'll want to create a surge token. From your local system, use the command surge token to generate the token. Save this value.

In your GitLab project, open CI/CD settings and create two variables with their respective values:

  • SURGE_LOGIN - the email address used for surge (this may actually be optional, based on my reading of the source)
  • SURGE_TOKEN - the token you just created using surge token

Then you can run your command (e.g. surge --project ./public --domain domain_aka_domain_any_name.surge.sh) and you won't be prompted for credentials.

  script:
    - npm install --global surge
    - surge --project ./public --domain domain_aka_domain_any_name.surge.sh

Upvotes: 1

Related Questions