Declarative Pipeline multiple agents Error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Declarative Pipeline multiple agents Error

Matthew Ceroni
I have the following example pipeline

#!/usr/bin/env groovy
@Library('shared-library@1.1.0') _

pipeline {
  agent {
    kubernetes {
      label buildId()
      containerTemplate {
        name 'node'
        image 'node:8.9.4-alpine'
        ttyEnabled true
        command 'cat'
      }
    }
  }
  stages {

    
    stage('Build') {
      steps {
        sh "echo npm run build"
        
        // stash build directory
        //stash includes: 'build/**', name: 'app'
      }
    }

    stage('Unit Test') {
      steps {
        script {
          try {
            sh "echo npm run test"
          } catch (err) {
            println "Failed"
          //} finally {
           // junit 'build/reports/**/*.xml'
          }
        }
      }
    }
    
    stage('Package') {
      agent { node { label 'docker1' } }
      options { skipDefaultCheckout() }
      steps {
        sh "/bin/sleep 120"
      }
    }
    
  }
}


What happens is that on the Package stage I get the following error:

[_location-service_PR-2-head-RP4JKIYE4QYJREC2YOQQGNKQG5UC56YLZET3VDC2IPW4C5FSH7EQ] Running shell script
sh: can't create /home/jenkins/workspace/_location-service_PR-2-head-RP4JKIYE4QYJREC2YOQQGNKQG5UC56YLZET3VDC2IPW4C5FSH7EQ@tmp/durable-de461dce/jenkins-log.txt: nonexistent directory

Since the node I am accessing in that step is a container I thought maybe it was a permissions issue. However I validated this wasn't the case by making that agent (node { label 'docker1' }} the top level agent and the pipeline runs fine. 

So my thought is that during the switch between agents/nodes it is expecting that directory to exist (it does create the workspace directory though, just not durable).

Any help would be appreciated.

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/cf5d0491-00ac-4c41-860f-49f926b9d461%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Declarative Pipeline multiple agents Error

Matthew Ceroni
Ran another test that seems to validate somewhat of what I said above. Instead of having a global agent I specified an agent per stage (2 stages)

In this situation the first agent created the workspace, checked out the code and the durable- directory existed.

When it got to the second stage and connected to the docker container it created the workspace but not the durable- directory but at the same time didn't complain about it like the above error message.


#!/usr/bin/env groovy
@Library('shared-library@1.1.0') _

pipeline {
  agent none
  stages {

    stage('Build') {
      agent {
        kubernetes {
          label buildId()
          containerTemplate {
            name 'node'
            image 'node:8.9.4-alpine'
            ttyEnabled true
            command 'cat'
          }
        }
      }
      steps {
        sh "echo npm run build"
        sh "/bin/sleep 120"
        
        // stash build directory
        //stash includes: 'build/**', name: 'app'
      }
    }

    stage('Package') {
      agent { node { label 'docker1' } }
      options { skipDefaultCheckout() }
      steps {
        sh "/bin/sleep 120"
      }
    }
    
  }
}







On Thursday, March 8, 2018 at 1:19:31 PM UTC-8, Matthew Ceroni wrote:
I have the following example pipeline

#!/usr/bin/env groovy
@Library('shared-library@1.1.0') _

pipeline {
  agent {
    kubernetes {
      label buildId()
      containerTemplate {
        name 'node'
        image 'node:8.9.4-alpine'
        ttyEnabled true
        command 'cat'
      }
    }
  }
  stages {

    
    stage('Build') {
      steps {
        sh "echo npm run build"
        
        // stash build directory
        //stash includes: 'build/**', name: 'app'
      }
    }

    stage('Unit Test') {
      steps {
        script {
          try {
            sh "echo npm run test"
          } catch (err) {
            println "Failed"
          //} finally {
           // junit 'build/reports/**/*.xml'
          }
        }
      }
    }
    
    stage('Package') {
      agent { node { label 'docker1' } }
      options { skipDefaultCheckout() }
      steps {
        sh "/bin/sleep 120"
      }
    }
    
  }
}


What happens is that on the Package stage I get the following error:

[_location-service_PR-2-head-RP4JKIYE4QYJREC2YOQQGNKQG5UC56YLZET3VDC2IPW4C5FSH7EQ] Running shell script
sh: can't create /home/jenkins/workspace/_location-service_PR-2-head-RP4JKIYE4QYJREC2YOQQGNKQG5UC56YLZET3VDC2IPW4C5FSH7EQ@tmp/durable-de461dce/jenkins-log.txt: nonexistent directory

Since the node I am accessing in that step is a container I thought maybe it was a permissions issue. However I validated this wasn't the case by making that agent (node { label 'docker1' }} the top level agent and the pipeline runs fine. 

So my thought is that during the switch between agents/nodes it is expecting that directory to exist (it does create the workspace directory though, just not durable).

Any help would be appreciated.

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/49f8742c-0210-4850-abd3-adb7928dd076%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Declarative Pipeline multiple agents Error

Matthew Ceroni
Take back what I said about the durable directory, they exist in both cases in this situation. So the below works. But if I have a global agent and try to over-ride that at a stage level I get the error about durable doesn't exist. 

On Thursday, March 8, 2018 at 1:28:04 PM UTC-8, Matthew Ceroni wrote:
Ran another test that seems to validate somewhat of what I said above. Instead of having a global agent I specified an agent per stage (2 stages)

In this situation the first agent created the workspace, checked out the code and the durable- directory existed.

When it got to the second stage and connected to the docker container it created the workspace but not the durable- directory but at the same time didn't complain about it like the above error message.


#!/usr/bin/env groovy
@Library('shared-library@1.1.0') _

pipeline {
  agent none
  stages {

    stage('Build') {
      agent {
        kubernetes {
          label buildId()
          containerTemplate {
            name 'node'
            image 'node:8.9.4-alpine'
            ttyEnabled true
            command 'cat'
          }
        }
      }
      steps {
        sh "echo npm run build"
        sh "/bin/sleep 120"
        
        // stash build directory
        //stash includes: 'build/**', name: 'app'
      }
    }

    stage('Package') {
      agent { node { label 'docker1' } }
      options { skipDefaultCheckout() }
      steps {
        sh "/bin/sleep 120"
      }
    }
    
  }
}







On Thursday, March 8, 2018 at 1:19:31 PM UTC-8, Matthew Ceroni wrote:
I have the following example pipeline

#!/usr/bin/env groovy
@Library('shared-library@1.1.0') _

pipeline {
  agent {
    kubernetes {
      label buildId()
      containerTemplate {
        name 'node'
        image 'node:8.9.4-alpine'
        ttyEnabled true
        command 'cat'
      }
    }
  }
  stages {

    
    stage('Build') {
      steps {
        sh "echo npm run build"
        
        // stash build directory
        //stash includes: 'build/**', name: 'app'
      }
    }

    stage('Unit Test') {
      steps {
        script {
          try {
            sh "echo npm run test"
          } catch (err) {
            println "Failed"
          //} finally {
           // junit 'build/reports/**/*.xml'
          }
        }
      }
    }
    
    stage('Package') {
      agent { node { label 'docker1' } }
      options { skipDefaultCheckout() }
      steps {
        sh "/bin/sleep 120"
      }
    }
    
  }
}


What happens is that on the Package stage I get the following error:

[_location-service_PR-2-head-RP4JKIYE4QYJREC2YOQQGNKQG5UC56YLZET3VDC2IPW4C5FSH7EQ] Running shell script
sh: can't create /home/jenkins/workspace/_location-service_PR-2-head-RP4JKIYE4QYJREC2YOQQGNKQG5UC56YLZET3VDC2IPW4C5FSH7EQ@tmp/durable-de461dce/jenkins-log.txt: nonexistent directory

Since the node I am accessing in that step is a container I thought maybe it was a permissions issue. However I validated this wasn't the case by making that agent (node { label 'docker1' }} the top level agent and the pipeline runs fine. 

So my thought is that during the switch between agents/nodes it is expecting that directory to exist (it does create the workspace directory though, just not durable).

Any help would be appreciated.

Thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/97ac2329-1926-4956-a974-c44341c6fd67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.