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

Error when using plugin in custom DSL #103

Closed
antoinedube opened this issue Dec 22, 2017 · 2 comments
Closed

Error when using plugin in custom DSL #103

antoinedube opened this issue Dec 22, 2017 · 2 comments

Comments

@antoinedube
Copy link

I am trying to extract a part of code that I will be reusing in different script. Currently, it is directly in the Jenkinsfile. For example:

stage('Check service directly from Jenkinsfile') {
     steps {
         script {
             openshift.withCluster("${OPENSHIFT_CLUSTER}") {
                 openshift.withProject("${OPENSHIFT_PROJECT}") {
                 def serviceSelector = openshift.selector('service', "${OPENSHIFT_SERVICE}")
                 def serviceDescription = serviceSelector.describe()
                 echo "service: ${serviceDescription}"
             }
         }
     }
 }

This is working as expected.

When extracting code in a groovy method (file vars/getServiceDescription.groovy):

def call(body) {
    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    body

    script {
        openshift.withCluster("${config.cluster}") {
            openshift.withProject("${config.project}") {
                def serviceSelector = openshift.selector('service', "${config.service}")
                def serviceDescription = serviceSelector.describe()
                echo "service: ${serviceDescription}"
            }
        }
    }
}

and calling it from my Jenkinsfile:

stage('Check service from external method') {
    steps {
        getServiceDescription cluster: "${OPENSHIFT_CLUSTER}", project: "${OPENSHIFT_PROJECT}", service: "${OPENSHIFT_SERVICE}"
    }
}

the resulting error/stacktrace is:

java.nio.file.NoSuchFileException: /var/run/secrets/kubernetes.io/serviceaccount/token
	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
	at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
	at java.nio.file.Files.newByteChannel(Files.java:361)
	at java.nio.file.Files.newByteChannel(Files.java:407)
	at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
	at java.nio.file.Files.newInputStream(Files.java:152)
	at hudson.FilePath.read(FilePath.java:1771)
	at org.jenkinsci.plugins.workflow.steps.ReadFileStep$Execution.run(ReadFileStep.java:96)
	at org.jenkinsci.plugins.workflow.steps.ReadFileStep$Execution.run(ReadFileStep.java:86)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
	at hudson.security.ACL.impersonate(ACL.java:260)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Any help would be appreciated.

@gabemontero
Copy link
Contributor

Hey @antoinedube - the expected and actual values of your cluster and project params/env vars when you run the different permutations are needed for me to fully help.

I can tell you that if the plugin sees empty values for the cluster parameter, it will go with among other things the default location of the jenkins service account token mounted in a pod, where the plugin will assume you are running in a jenkins pod.

My guess is that:
a) you are not running jenkins in an openshift pod based on the exception
b) and value for the cluster you expect to be passed into openshift.withCluster is not getting passed in, but rather the empty string is

@antoinedube
Copy link
Author

Hi,

Thanks for your input, it helped. It seems that point a) of your guess is right.

I will update my things knowing this.

Thanks.

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

2 participants