我有这个if else
语句,如果条件为真,则执行if
语句,但如果条件为假,则不执行else
语句
steps{
script{
echo '*Stage3 - Trying to build python program and export the Artifact*'
pyInstallerOutput = bat(returnStdout: true, script: '@python -m PyInstaller -v').trim()
if(!("$pyInstallerOutput".contains('No module named'))){
echo "+ PyInstaller Version: $pyInstallerOutput is up and running. good! building artifact"
directoryName = bat(returnStdout: true,script: '@echo %date:~-4,4%-%date:~-10,2%-%date:~7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%').trim()
echo ("+ Current Artifact directory: $directoryName")
artifactResult = bat(returnStdout: true, script: "@python -m PyInstaller --specpath ./artifacts-repo/${directoryName}/spec --distpath ./artifacts-repo/${directoryName}/dist --workpath ./artifacts-repo/${directoryName}/build --onefile ./codes/SayHello.py")
} else{
echo '- PyInstaller not installed on node, trying to install it'
installResult = bat(returnStdout: true, script: '@pip install pyinstaller')
if("$installResult".contains('Successfully installed')){
echo '+ PyInstaller installed successfully, Now building Artifact.'
directoryName = bat(returnStdout: true,script: '@echo %date:~-4,4%-%date:~-10,2%-%date:~7,2%-%time:~-11,2%%time:~-8,2%%time:~-5,2%')
echo ("+ Current Artifact directory: $directoryName")
artifactResult = bat(
returnStdout: true,
script: "@python -m PyInstaller --specpath ./artifacts-repo/${directoryName}/spec --distpath ./artifacts-repo/${directoryName}/dist --workpath ./artifacts-repo/${directoryName}/build --onefile ./codes/SayHello.py"
)
}else{
error('- PyInstaller installation failed, nothing more can be done by pipeline, STOPING')
}
}
}
}
当if
条件为真时记录
* Stage3 - Trying to build python program and export the Artifact*
[Pipeline] bat
[Pipeline] echo
+ PyInstaller Version: 5.5 is up and running. good! building artifact
[Pipeline] bat
[Pipeline] echo
+ Current Artifact directory: 2022-10-09-211243
[Pipeline] bat
376 INFO: PyInstaller: 5.5
376 INFO: Python: 3.10.7
384 INFO: Platform: Windows-10-10.0.22000-SP0
386 INFO: wrote ./artifacts-repo/2022-10-09-211243/spec\SayHello.spec
387 INFO: UPX is not available.
389 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Ata '
'System\\AppData\\Local\\Jenkins\\.jenkins\\workspace\\Pipeline-01\\codes']
840 INFO: checking Analysis
841 INFO: Building Analysis because Analysis-00.toc is non existent
841 INFO: Initializing module dependency graph...
843 INFO: Caching module graph hooks...
854 INFO: Analyzing base_library.zip ...
3125 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\Ata System\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\PyInstaller\\hooks'...
3188 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\Ata System\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\PyInstaller\\hooks'...
4729 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\Ata System\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\PyInstaller\\hooks'...
5910 INFO: Caching module dependency graph...
6004 INFO: running Analysis Analysis-00.toc
6011 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2032.0_x64__qbz5n2kfra8p0\python.exe
6207 INFO: Analyzing C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01\codes\SayHello.py
6209 INFO: Processing module hooks...
6219 INFO: Looking for ctypes DLLs
6221 INFO: Analyzing run-time hooks ...
6222 INFO: Including run-time hook 'C:\\Users\\Ata System\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
6224 INFO: Including run-time hook 'C:\\Users\\Ata System\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_subprocess.py'
6228 INFO: Looking for dynamic libraries
365 INFO: Extra DLL search directories (AddDllDirectory): []
366 INFO: Extra DLL search directories (PATH): ['C:\\Program Files (x86)\\VMware\\VMware Workstation\\bin\\', 'C:\\WINDOWS\\system32', 'C:\\WINDOWS', 'C:\\WINDOWS\\System32\\Wbem', 'C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\', 'C:\\WINDOWS\\System32\\OpenSSH\\', 'C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR', 'C:\\Program Files\\Microsoft VS Code\\bin', 'C:\\Program Files (x86)\\Xshell 7\\', 'C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common', 'C:\\Program Files\\Git\\cmd', 'C:\\Users\\Ata System\\AppData\\Local\\Microsoft\\WindowsApps', 'C:\\Program Files\\JetBrains\\PhpStorm 2022.2.1\\bin', 'C:\\xampp\\php', 'C:\\Users\\Ata System\\AppData\\Local\\GitHubDesktop\\bin', 'C:\\apps\\opt\\spark-3.3.0-bin-hadoop3\\bin', 'C:\\apps\\opt\\spark-3.3.0-bin-hadoop3\\bin', 'C:\\Program Files\\Java\\jdk-17\\bin']
7142 INFO: Looking for eggs
7142 INFO: Using Python library C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2032.0_x64__qbz5n2kfra8p0\python310.dll
7142 INFO: Found binding redirects:
[]
7144 INFO: Warnings written to C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01\artifacts-repo\2022-10-09-211243\build\SayHello\warn-SayHello.txt
7161 INFO: Graph cross-reference written to C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01\artifacts-repo\2022-10-09-211243\build\SayHello\xref-SayHello.html
7188 INFO: checking PYZ
7188 INFO: Building PYZ because PYZ-00.toc is non existent
7188 INFO: Building PYZ (ZlibArchive) C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01\artifacts-repo\2022-10-09-211243\build\SayHello\PYZ-00.pyz
7392 INFO: Building PYZ (ZlibArchive) C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01\artifacts-repo\2022-10-09-211243\build\SayHello\PYZ-00.pyz completed successfully.
7397 INFO: checking PKG
7398 INFO: Building PKG because PKG-00.toc is non existent
7398 INFO: Building PKG (CArchive) SayHello.pkg
8688 INFO: Building PKG (CArchive) SayHello.pkg completed successfully.
8690 INFO: Bootloader C:\Users\Ata System\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
8690 INFO: checking EXE
8690 INFO: Building EXE because EXE-00.toc is non existent
8690 INFO: Building EXE from EXE-00.toc
8690 INFO: Copying bootloader EXE to C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01\artifacts-repo\2022-10-09-211243\dist\SayHello.exe.notanexecutable
8693 INFO: Copying icon to EXE
8694 INFO: Copying icons from ['C:\\Users\\Ata System\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
8705 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
8705 INFO: Writing RT_ICON 1 resource with 3752 bytes
8705 INFO: Writing RT_ICON 2 resource with 2216 bytes
8705 INFO: Writing RT_ICON 3 resource with 1384 bytes
8705 INFO: Writing RT_ICON 4 resource with 37019 bytes
8705 INFO: Writing RT_ICON 5 resource with 9640 bytes
8705 INFO: Writing RT_ICON 6 resource with 4264 bytes
8705 INFO: Writing RT_ICON 7 resource with 1128 bytes
8707 INFO: Copying 0 resources to EXE
8707 INFO: Embedding manifest in EXE
8707 INFO: Updating manifest in C:\Users\Ata System\AppData\Local\Jenkins\.jenkins\workspace\Pipeline-01\artifacts-repo\2022-10-09-211243\dist\SayHello.exe.notanexecutable
8717 INFO: Updating resource type 24 name 1 language 0
8719 INFO: Appending PKG archive to EXE
8732 INFO: Fixing EXE headers
8947 INFO: Building EXE from EXE-00.toc completed successfully.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] echo
Attemping some cleanup works.
[Pipeline] echo
当if
条件不为真时,您可以看到else
被跳过!!!
* Stage3 - Trying to build python program and export the Artifact*
[Pipeline] bat
C:\Users\Ata System\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe: No module named PyInstaller
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] echo
Attemping some cleanup works.
[Pipeline] echo
你可以找到完整的jenkins文件Here
1条答案
按热度按时间v09wglhw1#
一个选项是用
try-catch
或catchError
块包围bat
命令