Jenkins Copy Artifact: "Unable to find project for artifact copy" when job is triggered by timer

66 views Asked by At

I have few multibranch projects on my jenkins:

MultiBranchA

  • master_branch
  • feature_branch1
  • feature branch2... etc

FolderB

  • MultiBranchB

    1. master_branch
  • MultiBranchC

    1. master_branch

Branches from Project A triggers build in one of multibranch pipelines in FolderB

stage("tests") {
    when {
        { return params.FunctionalTests }
    }
    steps {
       catchError(buildResult:"SUCCESS", stageResult: "FAILURE"){
           script {
               if (params.FunctionalTests && params.OtherParam)
               build wait: true, propagate: true, job: 'FolderB/MultiBranchA/master_branch', 
               parameters: [string(name: 'passTreshold', value: '100'), 
                            string(name: 'unstableTreshold', value: '90'), 
                            other params....]
             }
         }
    }
}

Triggered build (ProjectB) copy artifacts from upstream project

stage ("Copy artifacts") {

    steps {
        script {
            echo "Try to copy artifacts"    
            copyArtifacts (projectName:"MultiBranchA/master_branch, filter: "image_file.swu", 
                           selector: lastSuccessful(), fingerprintArtifacts: true)
        }
   }
}

And everything worked fine until we added time trigger to ProjectA

triggers {
  cron( env.BRANCH_NAME.equals('master_branch') ? '0 2 * * *' : '')
}

Now when timer triggers build in ProjectA and it triggers job in ProjectB, coppyArtifact command fails with:

Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: ff3884e9-3af0-4d44-b474-76708d907d64
hudson.AbortException: Unable to find project for artifact copy: ProjectA/master_branch
This may be due to incorrect project name or permission settings; see help for project name in job configuration.
    at hudson.plugins.copyartifact.CopyArtifact.perform(CopyArtifact.java:480)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

It fails only for jobs triggered by timer. I found information, that in this case copyArtifact plugin works with anonymous user permissions. We are using Role-based Authorization Strategy plugin and we don't want add read permissions for anonymous users.

I tried to add permissions to copy artifact in jenkinsfile of ProjectB (every possible option), didn't help

options {
    disableConcurrentBuilds()
    timestamps()
    buildDiscarder(logRotator(numToKeepStr:"10"))
    //copyArtifactPermission('MultiBranchA')
    //copyArtifactPermission('MultiBranchA/*')
    //copyArtifactPermission('MultiBranchA/master_branch')
    //copyArtifactPermission('*')
}

I also installed Authorize Project plugin but looks like it is not working well with multibranch pipelines, authorization side bar menu didn't show up. In "Manage Jenkins" > "Configure Global Security" > Access control for builds I added "Pre-project configurable build Authorization" and tried every possible option (run as system, run as specific user etc.), also didn't help. Any idea how to solve this?

0

There are 0 answers