プッシュして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 を実行し、発行したトークンを入力
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!