Question

How to run doctl from Gitlab CI?

Im trying to deploy my app from Gitlab CI, here is my gitlab-ci.yml

"Deploy to DigitalOcean":
  image: digitalocean/doctl:latest
  stage: deploy
  needs:
    - job: "Test Docker build"
  script:
    - doctl auth init
    - /app/doctl apps create-deployment XXX
  only:
    - master

Also I added the DIGITALOCEAN_ACCESS_TOKEN variable with my personal token. But I got an error

``Successfully extracted cache  ``Executing "step_script" stage of the job script 00:00 
``Using docker image sha256:16287ffaf3b998b10c7348803f2372d99b9daadc1f5ded9aab957f6b2b34a7e3 for digitalocean/doctl:latest with digest digitalocean/doctl@sha256:d612c781afeb2720393e32312ef19af545b5c69b933a02bcd83e3e2bda874802 ... 
``Error: unknown command "sh" for "doctl"
``Run 'doctl --help' for usage.
``Cleaning up project directory and file based variables 00:01
``ERROR: Job failed: exit code 255

How can I trigger DigitalOcean from my CI pipeline? I don’t want to use deploy_on_push feature, because it ignores my pipelines and deploy app even when my CI/CD is red.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I had to mix the @Bobby Iliev answer and hint from this SO answer.

Here is the final gitlab-ci.yml job:

"Deploy to DigitalOcean":
  image:
    name: digitalocean/doctl:latest
    entrypoint: [""]
  stage: deploy
  needs:
    - job: "Test Docker image"
  script:
    - /app/doctl auth init
    - /app/doctl apps create-deployment $DIGITALOCEAN_STUDENT_BACKEND_ID
  only:
    - master
Bobby Iliev
Site Moderator
Site Moderator badge
January 21, 2023

Hi there,

As you are getting Error: unknown command "sh" for "doctl", I think that you need to update the first doctl line from:

  script:
    - doctl auth init
    - /app/doctl apps create-deployment XXX

To:

  script:
    - /app/doctl auth init
    - /app/doctl apps create-deployment XXX

Let me know how it goes!

Best,

Bobby

deploy: stage: deploy image: name: digitalocean/doctl:1.97.1 entrypoint: [“”] script: - /app/doctl auth init - /app/doctl compute droplet create my-app --image docker-18-04 --size s-1vcpu-1gb --region nyc1 only: - main

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel