You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Polarion中如何获取项目下所有LiveDoc文档以用于Scheduler脚本?

Polarion 获取指定项目全量LiveDoc的调度器脚本实现

可以直接通过Polarion公开的Java/Groovy API实现该需求,不需要额外依赖,以下是可直接在Scheduler中运行的脚本示例:

核心实现逻辑

  • Polarion中LiveDoc对应的底层数据对象为IModule,类型标记为ModuleTypeEnum.LIVE_DOC
  • 所有数据查询操作需要在Polarion事务内执行,脚本中可直接调用平台内置服务获取数据

可直接复用的脚本示例

import com.polarion.alm.projects.IProjectService
import com.polarion.alm.tracker.ITrackerService
import com.polarion.alm.tracker.model.IModule
import com.polarion.platform.core.PlatformContext
import com.polarion.alm.tracker.model.ModuleTypeEnum
import com.polarion.platform.persistence.ITransactionService

// 替换为你的目标项目ID
def targetProjectId = "replace_with_your_project_id"
def resultLiveDocs = []

def transactionService = PlatformContext.getPlatform.lookupService(ITransactionService)
// 事务内执行查询避免数据不一致
transactionService.executeInTransaction {
    def projectService = PlatformContext.getPlatform.lookupService(IProjectService)
    def trackerService = PlatformContext.getPlatform.lookupService(ITrackerService)
    
    def targetProject = projectService.getProject(targetProjectId)
    if(!targetProject || targetProject.isUnresolvable()) {
        log.error("指定项目ID {} 不存在,请检查配置", targetProjectId)
        return
    }

    // 遍历项目下所有模块筛选LiveDoc
    trackerService.getModules(targetProject).each { module ->
        if(ModuleTypeEnum.LIVE_DOC == module.getType()) {
            // 可按需扩展需要提取的字段
            resultLiveDocs << [
                docId: module.getId(),
                docName: module.getName(),
                space: module.getSpace()?.getName() ?: "root",
                author: module.getAuthor()?.getName() ?: "unknown"
            ]
        }
    }
}

// 后续自定义业务逻辑,例如下载、同步、统计等
resultLiveDocs.each { doc ->
    log.info("LiveDoc查询结果:{}(空间:{})", doc.docName, doc.space)
}

注意事项

  • 脚本中内置的log对象输出的内容可在Polarion后台的调度器任务日志页查看
  • 若项目内LiveDoc数量超过1000,建议使用trackerService.queryModules()传入查询条件和分页参数执行分批查询,避免内存溢出
  • 调度器默认使用系统权限执行,如果需要限制访问范围,可在任务配置页指定执行用户,脚本会继承该用户的资源访问权限

内容的提问来源于stack exchange,提问作者Anas Hosami

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.18 15:36:06