首页 > 解决方案 > 无法在 Jenkins 中将文件 'xxx-dist.tar' 添加到 TAR 'xxx-dist.tar'

问题描述

我用 java 编写了一个 web 应用程序项目(比如 frs)。它由 frs-core 和 frs-ui 模块组成。core 由gradle 构建,ui 由node v9.5.0工具构建。之后,maven统一了两个模块并转换为 TAR 格式。但是当它最终想将它们连接在一起时,出现了以下错误:

The build folder is ready to be deployed. You may serve it with a static server:

  yarn global add serve   serve -s build

Find out more about deployment here:

  http://bitttttttt

:frs-ui:distTar FAILED

FAILURE: Build failed with an exception.

* What went wrong: Execution failed for task ':frs-ui:distTar'.
> Could not add file '/home/samat/workspace/ttbank_frs-2.Build/frs-ui/build/distributions/frs-ui-1.0.0-9dcad410730dbec6f401254f464582e2fa8cd838-build.tar' to TAR '/home/samat/workspace/ttbank_frs-2.Build/frs-ui/build/distributions/frs-ui-1.0.0-9dcad410730dbec6f401254f464582e2fa8cd838-build.tar'.

这是我的build.gradle配置

>     group = 'ir.samatco.frs'
>     version = '1.0.0'
> 
>     apply from: "$rootDir/gradle/ci.gradle" }
> 
> ext {
>     javaProjects = [':frs-core', ':frs-gateway'].collect { project it }
>     webProjects = [':frs-ui'].collect { project it } }
> 
> subprojects {
>     if (project in javaProjects) {
>         apply plugin: 'java'
>         sourceCompatibility = 1.7
>         targetCompatibility = 1.7
>         [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
>     }
> 
>     if (project in webProjects) {
>         task npmBuild(type: Exec) {
>             workingDir projectDir
>             executable 'npm'
>             args 'run', 'build'
>         }
>         task distTar(type: Tar) {
>             dependsOn npmBuild
>             baseName = "${project.name}-${project.version}"
>             compression 'gzip'
>             extension 'tar'
>             destinationDir = "$buildDir/distributions" as File
>             from('dist') { into('/') }
>         }
>         idea {
>             module { //                excludeDirs = [".tmp", "bower_components", "dist", "node_modules"].collect {
> file("$projectDir/$it") }
>                 excludeDirs = ["dist", "node_modules"].collect { file("$projectDir/$it") }
>                 sourceDirs = [file("$projectDir/src")]
>             }
>         }
>     }
> 
>     apply plugin: 'maven-publish'
> 
>     publishing {
>         publications {
>             maven(MavenPublication) {
>                 artifact distTar {
>                     classifier 'dist'
>                 }
>             }
>         }
>         repositories {
>             maven() {
>                 credentials {
>                     username project.nexus_user
>                     password project.nexus_pass
>                 }
>                 url "http://nexus.devsamat.ir/content/repositories/test/"
>             }
>         }
>     } }
> 
> task stage {
>     dependsOn subprojects*.publish }

引起“无法将文件...添加到 TAR ... ”的原因是什么,谢谢百万。

标签: jenkinspublishtar

解决方案


我找到了解决方案!故障模块是frs-ui,它与 build.gradle 文件中的webProject块有关。所以你应该根据以下更改 build.gradle:

if (project in webProjects) {
    task npmBuild(type: Exec) {
        logging.captureStandardOutput LogLevel.INFO
        logging.captureStandardError LogLevel.INFO
        inputs.dir "src"
        outputs.dir "build"
        if(Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'cmd', '/c', 'npm', 'run', 'build'
        } else {
            commandLine 'npm', 'run', 'build'
        }
    }
    task distTar(type: Tar) {
        dependsOn npmBuild
        baseName = "${project.name}-${project.version}"
        compression 'gzip'
        extension 'tar'
        destinationDir = "$buildDir/distributions" as File
        from('dist') { into('/') }
    }
    idea {
        module {
            excludeDirs = [".tmp", "dist", "node_modules"].collect { file("$projectDir/$it") }
            sourceDirs = [file("$projectDir/src")]
        }
    }
}

推荐阅读