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?

More than 1 year has passed since last update.

【Jenkins】Jenkinsの設定に直接Pipeline Scriptをかきたい

Last updated at Posted at 2023-10-22

サクッと試験的にパイプライン作ってみたい時はこちらの方がおすすめ。
わざわざJenkinsfileをリモートリポジトリに用意しなくていい。
デメリットは誤ってこのジョブを消しちゃったら何も残らないくらい。
スクリーンショット 2023-10-22 14.47.37.png

設定->パイプライン->Scriptに直接書けばいい

pipeline {
    agent any
    
    triggers {
        cron('H * * * *')
    }
    
    environment {
        USERNAME = 'USERNAME'
        HOSTNAME = 'HOSTNAME'

    }
  
    stages {
        
        stage('SSH and run script') {
            steps {
                sshagent(credentials: ['CREDENTIAL-ID']) {
                    sh '''
                        ssh ${USERNAME}@${HOSTNAME} "cd /PATH/ && bash FILENAME"
                    '''
                  }
            }
        }
        stage('Clean Workspace') {
            steps {
                cleanWs()
            }
        }
    }
}

USERNAME
HOSTNAME
CREDENTIAL-ID
PATH
FILENAME
だけ書き換えれば動きます。

内容は
1時間に1回、
USERNAMEアカウントでHOSTNAMEへSSH接続し(この際CREDENTIAL-IDによりJenkinsサーバとHOSTNAME間のノンパス設定済)、
PATHにcdしてFILENAMEを実行、
最後にワークスペースをクリア
です。

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?