1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ローカル環境でGitLab CI ジョブを動かす

Last updated at Posted at 2022-09-14

はじめに

GitLab CI の練習としてジョブを作成し、パイプラインを動かします。

前回記事: Dockerを用いたGitLab-CIローカル環境の作り方で作成したローカル環境のGitLab, GitLab-runner 上で行います。
使用するプロジェクトは引き続き ci-practice を使用します。

この記事では、とりあえずローカル環境でジョブが動くことを目標とします。

プロジェクトをClone

前回作成した環境から、ci-practiceプロジェクトをCloneします。
Docker ネットワークの外からのアクセスになるので、設定した 172.20.0.2localhostに読み替えます。

任意の作業ディレクトリで clone コマンドを打ってください。

git clone http://localhost/root/ci-practice.git

また、このディレクトリでの作業者名を変更しておきましょう。

git config --local user.name root
git config --local user.email ""

.gitlab-ci.ymlを作成

ci-practice プロジェクト直下で .gitlab-ci.ymlを作成します。
中身は以下のように書きます。

.gitlab-ci.yml
stages:
  - test
  - build

test-job:
  image: alpine
  script:
    - echo 'test'
  stage: test
  tags: 
    - local
  only:
    - main

build-job:
  image: alpine
  script:
    - echo 'build'
  stage: build
  tags:
    - local
  only:
    - main

これでmainブランチに対しプッシュなどの操作を行った場合、2つのジョブが流れるようになりました。

mainブランチにコミットして、プッシュしましょう。

実行確認

プッシュが終われば、http://localhost:80へアクセスし「CI/CD」 => 「Pipelines」 から結果を確認できます。
各ジョブのチェックマークを押すとログが見れます。

SS 2022-09-14 10.42.51.png
SS 2022-09-14 10.55.50.png

.gitlab-ci.ymlに記述したとおり、echo 'test'が実行されていますね。

おわりに

前回の環境構築のほうが予想以上に手間取ったため、こちらの記事はジョブの実行のみとしました。
.gitlab-ci.ymlの書き方については他のサイトを参照ください。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?