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 5 years have passed since last update.

JenkinsPipeline 複数ノードでジョブを並列実行するスクリプト

0
Posted at

TEMPフォルダの中身を削除するジョブを並列で実行するスクリプト。

def onlineComputers = []
stage("GetOnlineComputers") {
  onlineComputers = getOnlineComputers()
}


def builders = [:]
for (int i = 0; i < onlineComputers.size(); i++) {
	def onlineComputerName = onlineComputers[i].getName()
	builders[onlineComputerName] = {
		node(onlineComputerName) {
			stage('delete') {
				bat "if exist %temp% del /Q %temp%"
				bat "if exist %temp%\\* for /D %%1 in (%temp%\\*) do rmdir /s /q %%1"
			}
		}
	}
}
parallel builders

def getOnlineComputers() {
  def nodes = []  
  def allNodes = Jenkins.getInstance().getNodes()
  for (x in allNodes) {
    def node = x
    allNodes.each{node ->
      if (node.toComputer() && !node.toComputer().isOffline() && !node.toComputer().isTemporarilyOffline()) {
        nodes << node
      }
    }
  }
  return nodes
}
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?