Я пытаюсь создать образ asp. net docker по декларативному конвейеру jenkins, поток работает на подчиненном компьютере jenkins windows server2019, поэтому для запуска * 1022 необходимо использовать powershell * команда, версия powershell 5.1, когда я пишу docker параметр сборки buildlt в команде, она выполняется успешно, команда:
stage('Build Container') {
steps {
echo "Build Container ${IMAGE_NAME}:${TAG} ${DOCKERFILE_PATH}"
script {
powershell "docker build -t windowsservercoreiisremote-ltsc2019:test . --force-rm"
}
}
}
и вывод на консоль jenkins
Build Container windowsservercoreiisremote-ltsc2019:ef16889
C:\Users\Administrator\Documents\jenkins-test-slave\orkspace\windowsservercoreIISRemote-ltsc2019
[Pipeline] script
[Pipeline] {
[Pipeline] powershell
Sending build context to Docker daemon 64.51kB
Step 1/4 : FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8-windowsservercore-ltsc2019
---> a82e61390cbd
Step 2/4 : LABEL owner="SkIT" version="1.0" description="����垢蝞∠�IS憟辣��indowsservercore�����"
---> Using cache
---> 83e11b15dac2
Step 3/4 : RUN powershell Install-WindowsFeature Web-Mgmt-Service; New-ItemProperty -Path HKLM:\software\microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1 -Force; Set-Service -Name wmsvc -StartupType automatic; net user xxxx xxxx /ADD; net localgroup administrators iisadmin /add;
---> Using cache
---> db03397c278d
Step 4/4 : EXPOSE 80/tcp 443/tcp 8172/tcp
---> Using cache
---> 32d9d4a005b5
Successfully built 32d9d4a005b5
Successfully tagged windowsservercoreiisremote-ltsc2019:test
[Pipeline] }
[Pipeline] // script
[Pipeline] }
Но когда я использую переменные jenkins в команде powershell, например:
def IMAGE_NAME = 'windowsservercoreiisremote-ltsc2019'
def TAG = ''
stage('Set GITHASH & Tag') {
steps {
script {
echo 'Set GITHASH & Tag'
GITHASH = powershell(returnStdout: true, script: 'git rev-parse --short HEAD')
TAG = powershell(returnStdout: true, script: 'git rev-parse --short HEAD')
}
}
}
stage('Build Container') {
steps {
echo "Build Container ${IMAGE_NAME}:${TAG} ${DOCKERFILE_PATH}"
script {
powershell "docker build -t ${IMAGE_NAME}:${TAG} . --force-rm"
}
}
}
Сборка powersehll docker завершится неудачно, и вывод консоли jenkins будет
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build Container)
[Pipeline] echo
Build Container windowsservercoreiisremote-ltsc2019:ef16889
C:\Users\Administrator\Documents\jenkins-test-slave\orkspace\windowsservercoreIISRemote-ltsc2019
[Pipeline] script
[Pipeline] {
[Pipeline] powershell
powershell.exe : "docker build" requires exactly 1 argument.
雿 C:\Users\Administrator\Documents\jenkins-test-slave\workspace\windowsservercoreIISRemote-ltsc2019@tmp\durable-e5acf825\powershellWrapper.ps1:3 摮��:1
+ & powershell -NoProfile -NonInteractive -ExecutionPolicy Bypass -Comm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ("docker build" ...tly 1 argument.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
. : The term '--force-rm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Administrator\Documents\jenkins-test-slave\workspace\windowsservercoreIISRemote-ltsc2019@tmp\durable-e5acf8
25\powershellScript.ps1:2 char:4
+ . --force-rm
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (--force-rm:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
[Pipeline] }
[Pipeline] // script
[Pipeline] }
Я также пробую docker команду сборки в конвейере jenkins
stage('Build Container') {
steps {
echo "Build Container ${IMAGE_NAME}:${TAG} ${DOCKERFILE_PATH}"
script {
def buildImage = docker.build("${IMAGE_NAME}:${TAG}","--force-rm")
}
}
}
Но это также не сработало, похоже, что при запуске на powershell у него возникла ошибка.