Windows:为Jenkins代理自动检测、条带化、资源调配和装载AWS EC2临时磁盘

Windows:为Jenkins代理自动检测、条带化、资源调配和装载AWS EC2临时磁盘,windows,amazon-web-services,powershell,jenkins,Windows,Amazon Web Services,Powershell,Jenkins,我的windows build Agent for Jenkins在EC2中运行,我想利用来自“d”类型实例的临时磁盘(例如C5ad.4xl提供2 x 300GB NVMe)来利用这些磁盘上可用的高IO 因为它们是构建代理,所以驱动器的短暂性是好的。我需要的东西,将检测,供应和挂载这些磁盘作为一个驱动器在Windows中基本上无论大小和数量。我可以在Linux中轻松做到这一点(LVM或软件RAID等),但尽管2014年有实现这一点的指南,但它在Windows Server 2019和最新实例上似

我的windows build Agent for Jenkins在EC2中运行,我想利用来自“d”类型实例的临时磁盘(例如C5ad.4xl提供2 x 300GB NVMe)来利用这些磁盘上可用的高IO

因为它们是构建代理,所以驱动器的短暂性是好的。我需要的东西,将检测,供应和挂载这些磁盘作为一个驱动器在Windows中基本上无论大小和数量。我可以在Linux中轻松做到这一点(LVM或软件RAID等),但尽管2014年有实现这一点的指南,但它在Windows Server 2019和最新实例上似乎不起作用

同一篇文章提到了从Server 2012 R2添加的磁盘,但这些磁盘不支持将磁盘转换为动态磁盘(这是在原始文章的代码中由diskpart对其进行条带化所需的关键步骤),因此它们不能直接用于所需的操作


是否有其他选项可以动态执行此操作,最好是使用powershell(或类似工具),这些选项可以在引导时作为配置的一部分传递给Jenkins代理?

Windows现在有存储池,这些存储池可用于执行此处需要的操作。此代码成功检测到多个磁盘,将它们添加到条带化池,使用可用的最大大小,并将新卷装入驱动器号“E”:

这里有一些关于磁盘数量的假设,这些假设会根据实例类型而有所不同,但通常情况下,它会使用它找到的任何临时磁盘,如果有多个磁盘,它会在它们之间进行条带化,然后在创建/格式化卷后使用可用的整个磁盘大小。所有这些都可以包装在
中,并添加到Jenkins代理配置的用户数据部分,以便在引导时运行

# get a list of the disks that can be pooled
$PhysicalDisks = (Get-PhysicalDisk -CanPool $true)
# only take action if there actually are disks
if ($PhysicalDisks) {
    # create storage pool using the discovered disks, called ephemeral in the standard subsystem
    New-StoragePool –FriendlyName ephemeral -StorageSubSystemFriendlyName "Windows Storage*" –PhysicalDisks $PhysicalDisks
    # Create a virtual disk, striped (simple resiliency in its terms), use all space
    New-VirtualDisk -StoragePoolFriendlyName "ephemeral" -FriendlyName "stripedephemeral" -ResiliencySettingName Simple -UseMaximumSize
    # initialise the disk
    Get-VirtualDisk -FriendlyName 'stripedephemeral'|Initialize-Disk -PartitionStyle GPT -PassThru
    # create a partition, use all available size (this will pop up if you do it interactively to format the drive, not a problem when running as userdata via Jenkins config)
    New-Partition -DiskNumber 3 -DriveLetter 'E' -UseMaximumSize
    # format as NTFS to make it useable
    Format-Volume -DriveLetter E -FileSystem NTFS -Confirm:$false
    # this creates a folder on the drive to use as the workspace by the agent
    New-Item -ItemType Directory -Force -Path E:\jenkins\workspace
}