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

More than 1 year has passed since last update.

JenkinsジョブをJenkinsfileから作成する

Last updated at Posted at 2023-01-22

概要

GitHubで管理されているJenkinsfileからJenkinsジョブを作成する

  • Jenkinsfile作成
  • Jenkinsジョブ作成

事前準備

環境

Jenkins 2.375.2(本記事記載時点)

Jenkinsfile作成

Jenkinsfileの記法について

DeclarativeとScriptedの2つの記法が存在するが、公式ではDeclarativeを推奨しているため、
本記事はDeclarativeを前提とする。
またJenkinsfileではGroovyで処理を記載できる。

参考:公式ページ

サンプルコード

Helloをコンソールに出力するジョブのサンプル

pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                sh 'echo "Hello"'
            }
        }
    }
}

Jenkinsジョブの作成

手順

  1. Jenkinsにログイン

  2. 新規ジョブを作成 を押下

    1. 7.png
  3. ジョブ名を入力、「パイプライン」を選択して「OK」を押下
    8.png

  4. General > パイプライン > Pipeline script from SCM を選択
    9.png

  5. SMC > git を選択し、Jenkinsfileを管理しているGit情報を入力して「保存」を押下
    10.png

  6. job作成完了

  7. 作成後の動作確認

    1. 作成したジョブを「ビルド実行」から実行
      11.png
    2. コンソールログを確認し「Hello」が出力されていればOK
      12.png
1
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
1
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?