@@ -30,6 +30,7 @@ package job
30
30
import (
31
31
"context"
32
32
"fmt"
33
+ "github.com/TencentBlueKing/bk-ci/agent/src/third_components"
33
34
"github.com/pkg/errors"
34
35
"io"
35
36
"os"
@@ -460,17 +461,38 @@ func postLog(red bool, message string, buildInfo *api.ThirdPartyBuildInfo, logTy
460
461
}
461
462
}
462
463
464
+ const (
465
+ targetJreDir = "/usr/local/jre"
466
+ targetJre8Dir = "/usr/local/jre8"
467
+ )
468
+
463
469
// parseContainerMounts 解析生成容器挂载内容
464
470
func parseContainerMounts (buildInfo * api.ThirdPartyBuildInfo ) ([]mount.Mount , error ) {
465
471
var mounts []mount.Mount
466
472
467
- // 默认绑定本机的java用来执行worker
468
- mounts = append (mounts , mount.Mount {
469
- Type : mount .TypeBind ,
470
- Source : config .GAgentConfig .JdkDirPath ,
471
- Target : "/usr/local/jre" ,
472
- ReadOnly : true ,
473
- })
473
+ // 默认绑定本机的java用来执行worker,如果有jdk17优先用jdk17,否则用jdk8
474
+ if third_components .Jdk .Jdk17 .GetJavaOrNull () != "" {
475
+ mounts = append (mounts , mount.Mount {
476
+ Type : mount .TypeBind ,
477
+ Source : config .GAgentConfig .Jdk17DirPath ,
478
+ Target : targetJreDir ,
479
+ ReadOnly : true ,
480
+ })
481
+ // 用jdk17的同时保存jdk8
482
+ mounts = append (mounts , mount.Mount {
483
+ Type : mount .TypeBind ,
484
+ Source : config .GAgentConfig .JdkDirPath ,
485
+ Target : targetJre8Dir ,
486
+ ReadOnly : true ,
487
+ })
488
+ } else {
489
+ mounts = append (mounts , mount.Mount {
490
+ Type : mount .TypeBind ,
491
+ Source : config .GAgentConfig .JdkDirPath ,
492
+ Target : targetJreDir ,
493
+ ReadOnly : true ,
494
+ })
495
+ }
474
496
475
497
// 默认绑定本机的 worker 用来执行
476
498
mounts = append (mounts , mount.Mount {
@@ -534,6 +556,11 @@ func parseContainerEnv(dockerBuildInfo *api.ThirdPartyDockerBuildInfo) []string
534
556
envs = append (envs , "devops_gateway=" + config .GetGateWay ())
535
557
// 通过环境变量区分agent docker
536
558
envs = append (envs , "agent_build_env=DOCKER" )
559
+ // JDK版本,只有jdk17的过渡期需要这个
560
+ if third_components .Jdk .Jdk17 .GetJavaOrNull () != "" {
561
+ envs = append (envs , "DEVOPS_AGENT_JDK_8_PATH=" + (targetJre8Dir + "/bin/java" ))
562
+ envs = append (envs , "DEVOPS_AGENT_JDK_17_PATH=" + (targetJreDir + "/bin/java" ))
563
+ }
537
564
538
565
return envs
539
566
}
0 commit comments