0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ローカルで.gitlab-ci.ymlの検証(validation)する

Posted at

プッシュしてCI実行前に、ローカルで.gitlab-ci.ymlの検証(validation)したいよね。。。

1. gitlabのcli glab をインストール

brew install glab

2. .gitlab-ci.yml の構文チェックを実行

% glab ci lint
You must be in a GitLab project repository for this action.
Error: 1 error occurred:
	* kaihei777/sample-gitlab-project: 404 Not Found

3. 404 Not Foundになるので状況確認

glab の認証トークンが設定されていない

glab auth status

gitlab.com
  x gitlab.com: API call failed: GET https://gitlab.com/api/v4/user: 401 {message: 401 Unauthorized}
  ✓ Git operations for gitlab.com configured to use ssh protocol.
  ✓ API calls for gitlab.com are made over https protocol.
  ✓ REST API Endpoint: https://gitlab.com/api/v4/
  ✓ GraphQL Endpoint: https://gitlab.com/api/graphql/
  ! No token provided in configuration file.

x could not authenticate to one or more of the configured GitLab instances.

4. 未認証の場合 は、以下の手順でトークンを設定

  • GitLab の アクセストークン発行ページ にアクセス
    Personal access tokensを追加
    api スコープを持つアクセストークンを発行
  • glab auth login を実行し、発行したトークンを入力

スクリーンショット 2025-02-21 16.31.03.png

api
スクリーンショット 2025-02-21 16.33.49.png

glab auth login
? What GitLab instance do you want to log into? gitlab.com
- Logging into gitlab.com
? How would you like to sign in? Token

Tip: generate a personal access token at https://gitlab.com/-/user_settings/personal_access_tokens?scopes=api,write_repository.
The minimum required scopes are 'api' and 'write_repository'.
? Paste your authentication token: **************************
? Choose default Git protocol: SSH
- glab config set -h gitlab.com git_protocol ssh
✓ Configured Git protocol.
- glab config set -h gitlab.com api_protocol https
✓ Configured API protocol.
✓ Logged in as kaihei777
✓ Configuration saved to /Users/kaihei777/.config/glab-cli/config.yml

5. 再度、.gitlab-ci.yml の構文チェックを実行

glab ci lint    
Validating...
✓ CI/CD YAML is valid!
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?