我希望根据某些条件设置构建名称。
例如:
02-11 13:54:31.191 28199-28199/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: Changed directory to /storage/emulated
02-11 13:54:31.481 28199-28199/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: Changed directory to /storage
02-11 13:54:32.101 28199-28199/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: Selected index: 0
02-11 13:54:32.111 28199-28199/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: Changed directory to /storage/MicroSD
02-11 13:54:33.091 28199-28199/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: Selected index: 6
02-11 13:54:33.101 28199-28199/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: Changed directory to /storage/MicroSD/WhatsAppold
02-11 13:54:33.581 28199-28199/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: Returning /storage/MicroSD/WhatsAppold as result
02-11 13:54:33.581 28199-28255/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: FileObserver received event 32768
02-11 13:54:33.601 28199-28199/net.rdrei.android.dirchooser.sample D/DirectoryChooserFragment: Changed directory to /storage/MicroSD/WhatsAppold
02-11 13:54:33.601 28199-28199/net.rdrei.android.dirchooser.sample I/DirChooserSample: Return from DirChooser with result 1
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: java.io.FileNotFoundException: /storage/MicroSD/WhatsAppold/a.apk: open failed: EACCES (Permission denied)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at libcore.io.IoBridge.open(IoBridge.java:409)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at net.rdrei.android.dirchooser.sample.DirChooserSample.moveFile(DirChooserSample.java:109)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at net.rdrei.android.dirchooser.sample.DirChooserSample$3.onClick(DirChooserSample.java:76)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at android.view.View.performClick(View.java:4478)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at android.view.View$PerformClick.run(View.java:18698)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at android.os.Looper.loop(Looper.java:149)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5257)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at dalvik.system.NativeStart.main(Native Method)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at libcore.io.Posix.open(Native Method)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: at libcore.io.IoBridge.open(IoBridge.java:393)
02-11 13:54:35.601 28199-28199/net.rdrei.android.dirchooser.sample W/System.err: ... 15 more
我可以使用build name setter插件设置构建名称,但我需要根据条件。
答案 0 :(得分:6)
假设您使用自由样式作业,那么您可以使用Groovy
插件执行任意groovy代码,该代码可以访问构建和Jenkins的Java结构。
只需添加Execute system Groovy script
步骤并输入确定名称的代码,然后使用build.setDisplayName()
设置名称。
与您的示例类似,这里是一个名称设置器,它根据构建参数branch_name
的值设置名称:
if (build.buildVariableResolver.resolve("branch_name").equals('master')) {
build.setDisplayName("Master build #${build.getNumber()}")
} else if (build.buildVariableResolver.resolve("branch_name").equals('development')) {
build.setDisplayName("Development build #${build.getNumber()}")
} else {
build.setDisplayName("Other build #${build.getNumber()}")
}
答案 1 :(得分:1)
如果分支名称(输入参数)=开发然后构建名称= 发展
假设您将分支名称作为参数提供,并希望使用name setter plugin将构建名称设置为相同,则应该能够对其进行配置。
您可以在setter插件中使用与环境变量相同的参数名称 ${ENV,var="my-special-branch"}
答案 2 :(得分:0)
如果要通过参数为作业设置内部版本名称,可以使用
currentBuild.displayName = "${nameOfYourParameter}"
作业配置
使用参数构建作业
构建历史记录