Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

并行的情况下一个线程跑两个stage出现问题 #65

Open
Cccccc-c opened this issue Jan 6, 2023 · 0 comments
Open

并行的情况下一个线程跑两个stage出现问题 #65

Cccccc-c opened this issue Jan 6, 2023 · 0 comments

Comments

@Cccccc-c
Copy link

Cccccc-c commented Jan 6, 2023

中文社区的话,我就用中文了哈!!!
先上代码
QQ20230106-0
我通过这个代码实现了这样一个效果
飞书20230106-143917

启动配置都是这样的
QQ20230106-2

——————————————————————————————————-------——————————————————————————-
我现在想 实现这样的效果,一个线程 运行两个或两个以上的stage{}
大概效果是下面这张图的样子。
QQ20230106-0

代码是这样的,
QQ20230106-1

但是最后出来的图却是这样的
QQ20230106-0

看log的话两个stage都是跑了的

QQ20230106-1
但是却不能出现我想要的Blue Ocean 效果图

我还尝试过 将try代码块里面的,两个小stage用stages再包一下
结果报了这个错
QQ20230106-3

所以请求帮助 看一下我的问题 ,解一下我的疑惑,怎么才能出现我想要的效果

完整的代码

def run_on_board(service){
    stage1 = {
        def thing = null
        waitUntil {
            thing = latch.pollFirst();
            return thing != null;
        }
        try {
            stage('1') {
                withEnv(["service=${service}"]){
                    sh '''
                        echo "11"
                    '''
                }
            }
            stage('2') {
                withEnv(["service=${service}"]){
                    sh '''
                        echo "22"
                    '''
                }
            }
        }
        finally {
            latch.offer(thing)
        }
    }
  return stage1
}
pipeline {
    agent any
    environment {
      model_list = "${model_lists}"
      max_concurrent = "${max_concurrent}"
    }
    stages{
        stage('Run on board') {
            steps {
                script {
                    def stages = [:]
                    MAX_CONCURRENT = max_concurrent.toInteger()
                    latch = new java.util.concurrent.LinkedBlockingDeque(MAX_CONCURRENT)
                    for(int i=0; i<MAX_CONCURRENT; i++)
                        latch.offer("$i")
                    for (service in model_list.tokenize('\n')){
                        stages[service] = run_on_board(service)
                    }
                    parallel stages
                }
            }
        }
    }
}
@Cccccc-c Cccccc-c changed the title 一个很疑惑的问题 并行的情况下一个线程跑两个stage出现问题 Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant