Giter Site home page Giter Site logo

jenkinsci / jenkinsfile-runner Goto Github PK

View Code? Open in Web Editor NEW
1.1K 33.0 290.0 1.75 MB

A command line tool to run Jenkinsfile as a function

License: MIT License

Java 90.79% Dockerfile 4.77% Makefile 0.38% Shell 3.58% PowerShell 0.14% Ruby 0.27% Groovy 0.08%
jenkins jenkins-pipeline cli faas docker-image jenkinsfile jenkinsfile-runner hacktoberfest

jenkinsfile-runner's Introduction

Jenkinsfile Runner (Incubating project)

Use-cases

Target use cases include but not limited to:

  • Using Jenkins in a Function-as-a-Service context.

  • Assist editing and testing Jenkins Pipeline definitions and libraries locally.

  • Integration testing of Pipelines.

Quick Demo

The demo below demonstrates running of a simple Pipeline with Jenkinsfile Runner. It is based on the Vanilla distribution which includes the minimum required set of plugins for running pipelines.

Jenkinsfile Runner Demo

See this directory for the source codes of the demo. There are more demos available in the project.

Usage in command-line

Jenkinsfile Runner can be run in the command line or in Docker. To run it in the command line follow these steps:

  1. Download the Jenkinsfile Runner ZIP archive available in GitHub Releases.

    • There is also a standalone JAR option available there, but this is a preview-only feature (see issue #350).

    • Latest unreleased versions can be also built from source code. See the contributing guidelines if you want to build Jenkinsfile Runner on your own.

  2. Prepare the execution environment

  3. Run the Pipeline

Preparation

Jenkinsfile Runner bundle includes the Jenkins core and a minimum set of plugins. More plugins can be installed on-demand. If it is not needed, just skip this step.

To add plugins, create a directory and assemble all the plugins that you’d like to use with the build. There are two ways to do it:

  • Use the Plugin Installation Manager Tool to install plugins into a new plugin directory.

  • Run the Jenkins setup wizard and install the desired set of plugins. After that, the plugins can be retrieved from JENKINS_HOME/plugins.

Execution

Say you have your Git repository checked out at ~/foo that contains Jenkinsfile and your source code. You can now run Jenkinsfile Runner like this:

jenkinsfile-runner -w <path to war> -p <path to plugins> -f <path to Jenkinsfile>

Sample Jenkinsfile:

pipeline {
    agent any
    stages {
        stage('Print hello') {
            steps {
                echo 'Hello world!'
            }
        }
    }
}

Output:

$ ./app/target/appassembler/bin/jenkinsfile-runner -w /tmp/jenkins -p /tmp/jenkins_home/plugins -f ~/foo/ -a "param1=Hello&param2=value2"
Started
Resume disabled by user, switching to high-performance, low-durability mode.
[Pipeline] node
[Pipeline] {
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Print hello)
[Pipeline] echo
Hello world!
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

The exit code reflects the result of the build. The demo directory includes a few simple examples of Jenkinsfiles you can try out.

Command Line Interface (CLI)

The Jenkinsfile Runner CLI provides multiple advanced options and commands. The CLI is powered by picocli and args4j. To execute a command:

 jenkinsfile-runner <command>

Supported commands:

  • run - Runs the Jenkinsfile. This command also runs by default if no subcommands specified.

  • lint - Lints the Jenkinsfile without actually running it. Only applicable to Declarative Pipeline.

  • cli - Runs interactive Jenkins CLI from where you can access all standard Jenkins commands provided by the Jenkins core and installed plugins: list-plugins, groovy, groovysh, etc.

  • generate-completion - Generate bash/zsh completion script for Jenkinsfile Runner.

  • version - Shows the Jenkinsfile Runner version.

  • help - Displays help information about the specified command.

All commands provide additional CLI arguments which can be accessed through help methods.

Jenkins Instance Arguments

Some CLI commands, including run require a startup of the Jenkins controller instance within Jenkinsfile Runner.

Common arguments:

  • -w (--jenkins-war) FILE - Path to exploded Jenkins WAR directory. Depending on packaging, it may contain the entire WAR file or just resources to be loaded by the WAR file, for example Groovy hooks or extra libraries.

  • -jv (--jenkins-version) VAL : Jenkins version to use if the WAR file is not specified. Defaults to latest LTS.

  • -p (--plugins) FILE - Plugins required for the run. Should point to either a plugins.txt file or to a /plugins installation directory Defaults to plugins.txt.

Advanced arguments:

  • --jenkinsHome FILE - Path to the empty Jenkins Home directory to use for this run. If not specified a temporary directory will be created. Note that the specified folder will not be disposed after the run.

  • --mirror - Mirror site to be used to download plugins if plugins.txt is specified.

    • NOTE: This option will be reworked in the future once the Plugin Installation Manager tool is integrated

  • --withInitHooks FILE - Path to the Groovy init hooks directory Hooks can be also passed via WEB-INF/groovy.init.d/** directory within the Jenkins WAR resource loader defined in --jenkins-war.

  • --skipShutdown - Skips the Jenkins shutdown logic to improve performance. Jenkinsfile Runner will abort the instance instead of gracefully releasing the resources. For example, agent connections will not be terminated. Also, plugin @Terminator extensions will not be invoked. It may lead to undefined behavior in the system, including potential data loss. This option is considered safe for the Vanilla package with the default plugin set.

  • --httpPort - Port for exposing the web server and Jenkins Web UI from Jenkinsfile Runner. Disabled by default.

  • --httpPath - The root path/prefix for expositng the web server and Jenkins Web UI from Jenkinsfile Runner.

  • --openWebUI - Open Jenkins Web UI in the default browser, --httpPort is expected to be defined together with this option.

  • --waitOnExit - Keep Jenkinsfile Runner running upon job completion without various sleep() hacks in the Pipeline.

  • --agentPort - Port for connecting inbound Jenkins agents (over JNLP or WebSockets). Disabled by default.

Running Jenkinsfiles (run command)

This is the main command in Jenkinsfile Runner. It executes all types of Pipeline definitions supported by Jenkinsfile Runner. Usage:

 jenkinsfile-runner run -w [warPath] -p [pluginsDirPath] -f [jenkinsfilePath] [other options]

In addition to Jenkins instance arguments defined above, it supports the following options:

  • -f (--file) FILE - Path to Jenkinsfile (or directory containing a Jenkinsfile) to run, defaults to ./Jenkinsfile.

  • -a (--arg) - Parameters to be passed to the Pipeline job. Use multiple -a switches for multiple params. All parameters will be recognized by Jenkins as String values.

Advanced options:

  • --runWorkspace FILE - Path to the workspace of the run to be used within the node{} context. It applies to both Jenkins controller and agents if any.

  • -u (--keep-undefined-parameters) - Keep undefined parameters if set, defaults to false.

  • -ns (--no-sandbox) - Run Pipeline job execution without the sandbox environment and script security checks. Use at your own risk.

  • -n (--job-name) VAL - Name of the job the run belongs to, defaults to 'job'

  • -b (--build-number) N- Build number of the run, defaults to 1.

  • -c (--cause) VAL- A string describing the cause of the run. It will be attached to the build so that it appears in the build log and becomes available to plug-ins and pipeline steps.

  • --scm FILE - A YAML file defining the SCM and optional credentials to use with the SCM. If given, the SCM will be checked out into the workspace automatically in Declarative Pipelines, and will be available for use with checkout scm in Scripted Pipelines. Note that an SCM cannot currently be used with Pipeline as YAML. See this doc for more details.

Passing parameters

Any parameter values, for parameters defined on workflow job within parameters statement, can be passed to the Jenkinsfile Runner using -a or --arg switches in the key=value format.

$ ./app/target/appassembler/bin/jenkinsfile-runner \
  -w /tmp/jenkins \
  -p /tmp/jenkins_home/plugins \
  -f ~/foo/ \
  # pipeline has two parameters param1 and param2
  -a "param1=Hello" \
  -a "param2=value2"

Usage in Docker

Containerized Pipeline execution is one of the main Jenkinsfile Runner use-cases. The project provides official Docker images which can be used and extended for custom use-cases.

Vanilla Distribution

This repository provides the Vanilla distribution. This package includes the minimum required set of plugins for running pipelines, but it needs to be extended in order to run real-world pipelines. The image is available in the jenkins/jenkinsfile-runner repository on DockerHub.

Image Packs

There is a Jenkinsfile Runner Image Packs repository. It provides additional Docker images for common use-cases, e.g. for building Java projects with Maven or Gradle. Each image includes a set of Jenkins plugins, configurations and Pipeline libraries which are commonly used in the desired technology stack. Image packs are available in the experimental jenkins4eval/jenkinsfile-runner repository on DockerHub.

Running Jenkinsfile Runner in Docker

Jenkinsfile Runner images can be launched simply as…

    docker run --rm -v $(pwd)/Jenkinsfile:/workspace/Jenkinsfile jenkins/jenkinsfile-runner

Advanced options:

  • JAVA_OPTS environment variable can be passed to pass extra JVM arguments to the image

docker run --rm -e JAVA_OPTS="-Xms 256m" -v $PWD/test:/workspace jenkins/jenkinsfile-runner
  • In the Vanilla Dockerfile the master workspace is mapped to /build. This directory can be exposed as a volume. The Docker image generated with Custom War Packager maps the workspace to /build by default and it can be exposed as well. However it is possible to override that directory if both the -v docker option and the --runWorkspace Jenkinsfile Runner option are specified.

  • By default the JENKINS_HOME folder is randomly created and disposed afterwards. With the --runHome parameter in combination with the -v Docker option it is possible to specify a folder. e.g. docker run -v /local/Jenkinsfile:/workspace/Jenkinsfile -v /local/jenkinsHome:/jenkinsHome ${JENKINSFILE_RUNNER_IMAGE} --runHome /jenkinsHome. This way you can access the build metadata in <jenkinsHome>/jobs/job/builds/1, like the build.xml, logs, and workflow data, even after the container finished.

  • The -ns and -a options can be specified and passed to the image in the same way as the command line execution. Using a non-sandbox environment may pose potential security risks. We strongly encourage you not to use this mode unless it is strictly necessary and always with extreme care and at your own risk.

  • You may pass --cli to obtain an interactive Jenkins CLI session. To get an interactive Jenkins CLI shell in the container, pass -i -e FORCE_JENKINS_CLI=true to docker run as extra parameters.

  • If you want to change default parameters for plugins or workspace, you can get onto the container by overriding entrypoint - binary is placed in /app/bin/jenkinsfile-runner.

$ docker run --rm -it -v $PWD/test:/workspace --entrypoint bash jenkinsfile-runner:my-production-jenkins
root@dec4c0f12478:/src# cp -r /app/jenkins /tmp/jenkins
root@dec4c0f12478:/src# /app/bin/jenkinsfile-runner -w /tmp/jenkins -p /usr/share/jenkins/ref/plugins -f /workspace

Extending Jenkinsfile Runner

Jenkinsfile Runner provides a vanilla image which includes some plugins and configurations. Usually, it is not enough to run a real Jenkins Pipelines. It might be required to install extra plugins and tools, and then to configure Jenkins so that Pipelines can properly operate in the user environment.

There are 2 ways to extend Jenkinsfile Runner:

  • Using low-level management tools, including the --plugins command included in CLI.

  • Docker

    • A simple example that converts a Jenkins image into a JFR can be found here.

    • A more advanced example using the Custom WAR/Docker Packager which automates some build steps and allows managing Jenkinsfile Runner configuration via a single YAML file can be found here.

Reporting issues

Please use GitHub Issues to report defects and improvement ideas. If you see a security issue in the component, please follow the vulnerability reporting guidelines.

Project roadmap

See the roadmap here.

jenkinsfile-runner's People

Contributors

addihorn avatar agentgonzo avatar babusekaran avatar carlossg avatar cr1t-gym avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar fcojfernandez avatar geisterfurz007 avatar jainsahab avatar jglick avatar kohsuke avatar linuxsuren avatar literalplus avatar michaelneale avatar mostafahussein avatar ndeloof avatar notmyfault avatar oleg-nenashev avatar pierrebtz avatar reftel avatar rinckm avatar romanisb avatar rsvoboda avatar schnatterer avatar sladyn98 avatar steven-terrana avatar syurevich avatar toshke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jenkinsfile-runner's Issues

Add JCasC to the Jenkinsfile Runner Vanilla Package

https://github.com/jenkinsci/configuration-as-code-plugin is the base way to configure Jenkins modern instances, and it works well with Jenkinsfile Runner.

Acceptance criteria:

  • The plugin dependency is added to the bundle. Version can be taken from BOM
  • JCasC directory is exposed as a volume so that users can append their configs
  • There is a documentation section JCasC with Jenkinsfile Runner
  • There is a demo created which demonstrates how to use the plugin inside Jenkinsfile Runner

FYI @Casz @timja

Document ways to include shared libraries when running jenkinsfile-runner

Just curious if there is anyway to load shared-libraries when jenkinsfile-runner invokes the pipeline. I read the comment below from (#23) from a year go, wondering if not currently supported would it be in the roadmap?

jenkinsfile-runner in it's current design only can run a Jenkinsfile that can execute on a green field jenkins installation without any specific setup. So tons of use cases won't be supported, like using tool installations, credentials, variables, plugins with specific configuration, and ... shared libraries.

For those, we need jenkinsfile-runner to include some jenkins configuration, and I indeed would like to get JCasC used for this purpose.

How to mock steps using withCredentials types "string", "usernamePassword", etc?

  • How can we simulate this locally?
  • Is there a way to mock this during running the container?
    • Some sort of volume, creating the expected file loaded by Jenkins?
    • Anything that would make this step run successfully?
withCredentials([string(credentialsId: "github.company.com-token", variable: "GITHUB_TOKEN")]) {
          echo "Getting the deploy repo ${paas.gitflow.to.git.repo.replace("github", GITHUB_TOKEN + ":@github")}"
          sh "git clone ${paas.gitflow.to.git.branch} ${paas.gitflow.to.git.repo.replace("github", GITHUB_TOKEN + ":@github")} ${paas.gitflow.to.git.cloneDir}"
          sh "ls -la ${paas.gitflow.to.git.cloneDir}"
        }

Logs

$ docker run -v $(pwd):/workspace marcellodesales/jenkinsfile-runner
Started
Running in Durability level: PERFORMANCE_OPTIMIZED
[Pipeline] node
Running on Jenkins in /tmp/jenkinsTests.tmp/jenkins3550020107483346587test/workspace/job
[Pipeline] {
[Pipeline] stage
[Pipeline] }
...
...
...
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException: Could not find credentials entry with ID 'github.company.com-token'
	at org.jenkinsci.plugins.credentialsbinding.MultiBinding.getCredentials(MultiBinding.java:153)
	at org.jenkinsci.plugins.credentialsbinding.impl.StringBinding.bindSingle(StringBinding.java:62)
	at org.jenkinsci.plugins.credentialsbinding.Binding.bind(Binding.java:150)
	at org.jenkinsci.plugins.credentialsbinding.impl.BindingStep$Execution.start(BindingStep.java:114)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:108)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62

Include Plugin Management Scripts into the Vanilla image

Eventiually I would like to make jenkins4eval/jenkinsfile-runner extensible in classic Docker ways, and plugin management is one of the common features there. The image used to include the plugin management scripts to include Declarative Pipeline, but it was removed in #187 .

It would be nice to restore bundling of plugin management scripts into the image. Then it can be documented for #189

Create a Declarative Pipeline demo

There is no Declarative Pipeline demo for the Vanilla packaging. It would be great to have one so that later it can be used for test automation.

java.lang.UnsupportedOperationException: Refusing to marshal io.jenkins.jenkinsfile.runner.SetJenkinsfileLocation for security reasons

When running the Jenkinsfile from Readme.md with the current version of the docker image (basing on Jenkins 2.108 and its default plugins) Jenkinsfile-runner fails with a UnsupportedOperationException:
It has also been reported on Google Groups.
Jenkinsfile:

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Hello world!'
                sh 'ls -la'
            }
        }
    }
}

Full stacktrace:

java.lang.UnsupportedOperationException: Refusing to marshal io.jenkins.jenkinsfile.runner.SetJenkinsfileLocation for security reasons; see https://jenkins.io/redirect/class-filter/
	at hudson.util.XStream2$BlacklistedTypesConverter.marshal(XStream2.java:543)
	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:88)
	at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.writeItem(AbstractCollectionConverter.java:64)
	at com.thoughtworks.xstream.converters.collections.CollectionConverter.marshal(CollectionConverter.java:74)
	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller$1.convertAnother(AbstractReferenceMarshaller.java:84)
	at hudson.util.RobustReflectionConverter.marshallField(RobustReflectionConverter.java:265)
	at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:252)
Caused: java.lang.RuntimeException: Failed to serialize hudson.model.Actionable#actions for class org.jenkinsci.plugins.workflow.job.WorkflowRun
	at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:256)
	at hudson.util.RobustReflectionConverter$2.visit(RobustReflectionConverter.java:224)
	at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.visitSerializableFields(PureJavaReflectionProvider.java:138)
	at hudson.util.RobustReflectionConverter.doMarshal(RobustReflectionConverter.java:209)
	at hudson.util.RobustReflectionConverter.marshal(RobustReflectionConverter.java:150)
	at com.thoughtworks.xstream.core.AbstractReferenceMarshaller.convert(AbstractReferenceMarshaller.java:69)
	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:58)
	at com.thoughtworks.xstream.core.TreeMarshaller.convertAnother(TreeMarshaller.java:43)
	at com.thoughtworks.xstream.core.TreeMarshaller.start(TreeMarshaller.java:82)
	at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.marshal(AbstractTreeMarshallingStrategy.java:37)
	at com.thoughtworks.xstream.XStream.marshal(XStream.java:1026)
	at com.thoughtworks.xstream.XStream.marshal(XStream.java:1015)
	at com.thoughtworks.xstream.XStream.toXML(XStream.java:988)
	at hudson.XmlFile.write(XmlFile.java:193)
	at org.jenkinsci.plugins.workflow.support.PipelineIOUtils.writeByXStream(PipelineIOUtils.java:30)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.save(WorkflowRun.java:1070)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils.updateRunAndJobActions(Utils.groovy:288)
	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils$updateRunAndJobActions$4.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:19)
Caused: java.io.IOException
	at hudson.XmlFile.write(XmlFile.java:200)
	at org.jenkinsci.plugins.workflow.support.PipelineIOUtils.writeByXStream(PipelineIOUtils.java:30)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.save(WorkflowRun.java:1070)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:47)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils.updateRunAndJobActions(Utils.groovy:288)
	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils$updateRunAndJobActions$4.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:19)
	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/app/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:61)
	at WorkflowScript.run(WorkflowScript:1)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
	at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:76)
	at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:331)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:82)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	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)

can not execute Jenkinsfile

I follow these steps

  1. unzip jenkins.war -d ~/opt/jenkins
  2. JENKINS_HOME=~/opt/jenkins_home java -jar jenkins.war
  3. install the recommed plugins from web http://localhost:8080/
    to exec ./bin/jenkinsfile-runner -w ~/opt/jenkins -p ~/opt/jenkins_home/plugins -f ~/projects/jenkins/hello/
    but failed. error bellow:
java.lang.NoSuchMethodError: No such DSL method 'pipeline' found among steps [archive, bat, catchError, checkout, deleteDir, dir, echo, error, fileExists, getContext, isUnix, load, mail, node, parallel, powershell, properties, pwd, readFile, readTrusted, resolveScm, retry, sh, sleep, stash, step, timeout, tool, unarchive, unstable, unstash, waitUntil, warnError, withContext, withEnv, wrap, writeFile, ws] or symbols [all, always, apiToken, architecture, archiveArtifacts, artifactManager, batchFile, booleanParam, buildButton, buildDiscarder, caseInsensitive, caseSensitive, choice, choiceParam, clock, cloud, command, cron, crumb, defaultView, demand, disableConcurrentBuilds, disableResume, downloadSettings, downstream, dumb, durabilityHint, envVars, file, fileParam, filePath, fingerprint, frameOptions, freeStyle, freeStyleJob, fromScm, fromSource, headRegexFilter, headWildcardFilter, hyperlink, hyperlinkToModels, installSource, jdk, jnlp, jobName, lastDuration, lastFailure, lastGrantedAuthorities, lastStable, lastSuccess, legacy, list, local, location, logRotator, loggedInUsersCanDoAnything, masterBuild, maven, maven3Mojos, mavenErrors, mavenMojos, mavenWarnings, myView, nodeProperties, none, overrideIndexTriggers, paneStatus, parameters, password, pattern, permanent, pipelineTriggers, plainText, plugin, pollSCM, projectNamingStrategy, proxy, queueItemAuthenticator, quietPeriod, rateLimitBuilds, run, runParam, schedule, scmRetryCount, scriptApproval, scriptApprovalLink, search, security, shell, slave, sourceRegexFilter, sourceWildcardFilter, stackTrace, standard, status, string, stringParam, swapSpace, text, textParam, tmpSpace, toolLocation, unsecured, upstream, userSeed, viewsTabBar, weather, zfs, zip] or globals [currentBuild, env, params, scm]
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:202)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:160)
	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:157)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:142)
	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:158)
	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:162)
	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
	at WorkflowScript.run(WorkflowScript:1)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:84)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:186)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:370)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:93)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:282)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:270)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:66)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
	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)
Finished: FAILURE

jenkins version: Jenkins 2.204.1

hello Jenkinsfile

pipeline {
   agent any

   stages {
      stage('Hello') {
         steps {
            echo 'Hello World'
         }
      }
   }
}

Serverless "one-shot" masters

On a large Jenkins deployment one might want to offload jenkins master to some "side" masters for pipeline execution.

We could rely on jenkinsfile-runner for such a "one-shot" master, applying #15 for configuration with adequate configuration scoped to a specific job, and on completion sync back build results to the main jenkins master (comparable to build-publisher plugin).

A full featured implementation would require some architecture effort for jenkins to be a cloud-native citizen, but it sounds to me we could rely on jenkinsfile-runner to demonstrate such a deployment and check interest for community in this direction.

cc @carlossg

[JENKINS-56270] - Static HTML build result

Hi everyone,

I love the Jenkinsfile runner, it is great to run Jenkins pipelines in environments like travis for example. I documented what I did there in a blog post.

Still, this approach has one large disadvantage: You lose the whole UI, which is of course helpful dig into build failures or see how your test coverage is doing.

My question: Is there anything that can generate a static HTML page which gives me the value that the Jenkins build overview page has? I understand that this is not static HTML in Jenkins, but I think in combination with Jenkinsfile runner and GitHub Pages, this could be very powerful.

Any hints on existing tools/plugins are highly appreciated.

Thanks for the great work in this plugin and Jenkins in general.

Add Declarative Pipeline to the standard bundle

Currently Declarative Pipeline is not included in https://github.com/jenkinsci/jenkinsfile-runner/tree/master/payload-dependencies , but it is bundled into the Dockerfile's plugins.txt ti means there is no verification of the plugin until #172 is implemented with some test automation, and the plugin may just fail to start.

I suggest Declarative Pipeline is added to Jenkinsfile Runner explicitly, and that the plugins.txt hack is removed from the Vanilla Docker image

WARNING hudson.util.PluginServletFilter#addFilter: Filter instance is registered too early:

always got this warn ,whole warn content as

2019-11-07 02:35:13.336+0000 [id=22]    WARNING hudson.util.PluginServletFilter#addFilter: Filter instance is registered too early: jenkins.telemetry.impl.UserLanguages$AcceptLanguageFilter@2a
java.lang.Exception
        at hudson.util.PluginServletFilter.addFilter(PluginServletFilter.java:108)
        at jenkins.telemetry.impl.UserLanguages.setUpFilter(UserLanguages.java:102)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104)
        at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175)
        at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
        at jenkins.model.Jenkins$5.runTask(Jenkins.java:1095)
        at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
        at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
        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)

how can i fix the warn ?

mvn compile error on Mac

I get an error compiling the jenkinsfile-runner.

Command:
mvn compile dependency:resolve dependency:resolve-plugins

java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.498 s
[INFO] Finished at: 2020-03-04T14:17:04-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project bootstrap: Compilation failure: Compilation failure: 
[ERROR] /private/tmp/jenkinsfile-runner/bootstrap/src/main/java/io/jenkins/jenkinsfile/runner/bootstrap/Bootstrap.java:[10,24] cannot find symbol
[ERROR]   symbol:   class PostConstruct
[ERROR]   location: package javax.annotation
[ERROR] /private/tmp/jenkinsfile-runner/bootstrap/src/main/java/io/jenkins/jenkinsfile/runner/bootstrap/Bootstrap.java:[138,6] cannot find symbol
[ERROR]   symbol:   class PostConstruct
[ERROR]   location: class io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap
[ERROR] -> [Help 1]

Add Pipeline Utility Steps to the Vanilla Package

https://plugins.jenkins.io/pipeline-utility-steps is widely used for operations like YAML processing, and it would be great to have it as a part of the default package so that users do not need to extend the image just to get this plugin installed.

Acceptance criteria:

stage('Read Evergreen YAML') {
    node {
        // Discover core version using Pipeline utility steps
        sh 'wget https://raw.githubusercontent.com/jenkins-infra/evergreen/master/services/essentials.yaml'
        def essentialsYaml = readYaml(file: "essentials.yaml")
        echo "Jenkins Evergreen uses the following Core version: ${essentialsYaml.spec.core.version}"
    }
}

Deploy a CD flow for the Windows Vanilla images

After #206 by @slide we still need to setup a delivery flow for these images so that they can be actually used from the jenkins4eval DockerHub organization.

ci.jenkins.io Does not seem to be stable enough ATM, we might need alternate solution.

Add support of routing STDIN from files in the --cli mode

It is a follow-up to #207 by @xxyy . Currently the Jenkins CLI works well in the interactive mode, but only few commands there actually make sense. We could extend the feature by supporting passing STDIN via a file so that we could get commands like create-job operational inside jenkinsfile runner.

Suggested syntax:

> create-job foo <config.xml
> build foo

Later it can be extended by a create-job flavor which takes Jenkinsfile as an argument, instead XML

[JENKINS-56267] - introduce support for "dry-run" in Pipeline

jenkinsfile-runner allows to run Pipeline on developer's workstation before it get committed to SCM and ran by Jenkins. This prevents SCM history to look like

  • Update Jenkinsfile to do some interesting stuff
  • fix Jenkinsfile
  • fix Jenkinsfile
  • fix Jenkinsfile
  • ...

On the other hand, running Pipeline on developer's workstation might not be feasible as the pipeline will have various side effects. You probably don't want to trigger a production deployment from your laptop while testing a fix.

I suggest we introduce support in jenkinsfile-runner for a Dry-Run mode in Pipeline execution. This will require explicit support in pipeline steps / shared libraries so they check for valid parameters but don't actually run stuff.

Same should apply to plain sh steps. For those I suggest we define environment variable DRY_RUN as a convention for script authors to support this use case. jenkinsfile-runner when set to run in dry-run mode would then take care to inject this to build environment.

I'm submitting this proposal as a github issue for initial feedback loop before I start writing some more concrete proposal as a doc in jenkinsfile-runner repository.

Git Server Plugin should not start the SSH server inside JFR

Follow-up to #184

Pipeline: Global CPS Library includes the Git Server Plugin which cannot be properly loaded without SSHD Module. There is no practical use-cases for having SSH Server inside JFR, and I suggest to find a way to exclude the functionality from Jenkinsfile Runner to optimize performance.

2019-10-09 12:08:30.498+0000 [id=27]    WARNING hudson.ExtensionFinder$Sezpoz#scout: Failed to scout org.jenkinsci.plugins.gitserver.ssh.SshCommandFactoryImpl
java.lang.ClassNotFoundException: org.jenkinsci.main.modules.sshd.SshCommandFactory
        at jenkins.util.AntClassLoader.findClassInComponents(AntClassLoader.java:1373)
        at jenkins.util.AntClassLoader.findClass(AntClassLoader.java:1326)
        at jenkins.util.AntClassLoader.loadClass(AntClassLoader.java:1079)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Caused: java.lang.NoClassDefFoundError: org/jenkinsci/main/modules/sshd/SshCommandFactory
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at jenkins.util.AntClassLoader.defineClassFromData(AntClassLoader.java:1139)
        at hudson.ClassicPluginStrategy$AntClassLoader2.defineClassFromData(ClassicPluginStrategy.java:707)
        at jenkins.util.AntClassLoader.getClassFromStream(AntClassLoader.java:1310)
        at jenkins.util.AntClassLoader.findClassInComponents(AntClassLoader.java:1363)
        at jenkins.util.AntClassLoader.findClass(AntClassLoader.java:1326)
        at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at jenkins.ClassLoaderReflectionToolkit.invoke(ClassLoaderReflectionToolkit.java:44)
        at jenkins.ClassLoaderReflectionToolkit._findClass(ClassLoaderReflectionToolkit.java:81)
        at hudson.PluginManager$UberClassLoader.findClass(PluginManager.java:2045)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Caused: java.lang.InstantiationException
        at net.java.sezpoz.IndexItem.element(IndexItem.java:146)
        at hudson.ExtensionFinder$Sezpoz.scout(ExtensionFinder.java:736)
        at hudson.ClassicPluginStrategy.findComponents(ClassicPluginStrategy.java:333)
        at hudson.ExtensionList.load(ExtensionList.java:381)
        at hudson.ExtensionList.ensureLoaded(ExtensionList.java:317)
        at hudson.ExtensionList.getComponents(ExtensionList.java:183)
        at jenkins.model.Jenkins$6.onInitMilestoneAttained(Jenkins.java:1126)
        at jenkins.InitReactorRunner$1.onAttained(InitReactorRunner.java:83)
        at org.jvnet.hudson.reactor.ReactorListener$Aggregator.lambda$onAttained$3(ReactorListener.java:102)
        at org.jvnet.hudson.reactor.ReactorListener$Aggregator.run(ReactorListener.java:109)
        at org.jvnet.hudson.reactor.ReactorListener$Aggregator.onAttained(ReactorListener.java:102)
        at org.jvnet.hudson.reactor.Reactor$1.run(Reactor.java:177)
        at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
        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)

Reporting as a bug

Allow passing a compressed WAR file in the '--war' argument

Currently --war option takes a part to the unzipped WAR file directory. Although it is good from the performance point of view, it causes confusion since Jenkinsfile Runner shows an odd behavior (classloading failures) when a WAR file is passed.

I suggest the following behavior:

  • If a WAR file is passed, Jenkinsfile Runner automatically unpacks it to a temporary directory OR to a work directory.
    ** In the case of the work directory (sharing between runs), a checksum should be calculated and persisted somehow to avoid collisions when a source war is changed. Such caching is not mandatory IMHO
  • When the option points to a WAR instead of the folder, a warning is printed to indicate the performance implications (WAR unpacking)

CC @btk3000

Replace custom plugin management implementation by Plugin Installation Manager

The custom implementation of Jenkinsfile Runner plugin management should be replaced by https://github.com/jenkinsci/plugin-installation-manager-tool/ so that there is no duplication and unexpected behavior

Depends on:

Original request

Hi,

im trying to insert plugins via plugin.txt into the pre-built image as stated out in readme.md of this project. Unfortunately it always fails. I guess its because it cant determine the version of the .war file and therefore loads incorrect dependencies.

I guess it is trying to download the latest dependencies but as the image from this repos master branch is 2.176.2, it fails.

FROM jenkins4eval/jenkinsfile-runner
COPY plugins.txt /usr/share/jenkins/ref/plugins.txt
RUN cd /app/jenkins && jar -cvf jenkins.war *
RUN java -jar /app/bin/jenkins-plugin-manager.jar --war /app/jenkins/jenkins.war --plugin-file /usr/share/jenkins/ref/plugins.txt && rm /app/jenkins/jenkins.war

See here the line "Unable to get version from war file."

Reading in plugins from /usr/share/jenkins/ref/plugins.txt

No directory to download plugins entered. Will use default of /usr/share/jenkins/ref/plugins
Using update center https://updates.jenkins.io from JENKINS_UC environment variable
No CLI option or environment variable set for experimental update center, using default of https://updates.jenkins.io/experimental
No CLI option or environment variable set for incrementals mirror, using default of https://repo.jenkins-ci.org/incrementals
Will use war file: /app/jenkins/jenkins.war
Unable to get version from war file

Downloading plugin ace-editor from url: https://updates.jenkins.io/download/plugins/ace-editor/1.0.1/ace-editor.hpi

The plugin download works of course but when i start my jenkins docker image I end up in dependency and unsupported version errors:

Leon$ docker run --rm -v $(pwd)/Jenkinsfile:/workspace/Jenkinsfile -v $(pwd)/config/jenkins.yaml:/usr/share/jenkins/ref/casc/jenkins.yaml 530bb9b3e3a2
2020-02-14 05:41:23.301+0000 [id=24]	SEVERE	jenkins.InitReactorRunner$1#onTaskFailed: Failed Loading plugin Pipeline Utility Steps v2.5.0 (pipeline-utility-steps)
java.io.IOException: Pipeline Utility Steps version 2.5.0 failed to load.
 - Pipeline: Groovy version 2.56 is older than required. To fix, install version 2.58 or later.
	at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:868)
	at hudson.PluginManager$2$1$1.run(PluginManager.java:544)
	at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
	at jenkins.model.Jenkins$5.runTask(Jenkins.java:1095)
	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
	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)
2020-02-14 05:41:23.307+0000 [id=23]	SEVERE	jenkins.InitReactorRunner$1#onTaskFailed: Failed Loading plugin Credentials Plugin v2.3.1 (credentials)
java.io.IOException: Credentials Plugin version 2.3.1 failed to load.
 - Configuration as Code Plugin version 1.32 is older than required. To fix, install version 1.35 or later.
	at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:868)
	at hudson.PluginManager$2$1$1.run(PluginManager.java:544)
	at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169)
	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
	at jenkins.model.Jenkins$5.runTask(Jenkins.java:1095)
	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
	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)
...

What im doing wrong?

Thanks for your help!

[JENKINS-56269] - support Environment & Secrets

Considering jenkinsfile-runner as a tool to run a Pipeline on developer's workstation, before it get committed and ran by a classic Jenkins master, we miss ability to set Environment and Secrets.

My proposal is to rely on configuration-as-code to describe in a concise, human-friendly way the set of tools / credentials / xx required for pipeline execution. jenkinsfile-runner would by default look for a Jenkinsfile-master.yaml aside the Jenkinsfile to run. This file can be committed side by side with the Jenkinsfile for easier reproducibility by teammates.

To avoid credentials stored in SCM in clear text, I propose to rely on a Jenkinsfile-secrets credentials file (comparable to docker-secrets, already supported by CasC). This file would be encrypted, the same way CodeShip does, so it can be committed in SCM as well. When ran, jenkinsfile-runner would decrypt this file in memory and use it to configure the transient master and run pipeline.

I'm submitting this proposal as a github issue for initial feedback loop before I start writing some more concrete proposal as a doc in jenkinsfile-runner repository.

Loading @Library Error: Could not find any definition of libraries [github.com/mozmeao/jenkins-pipeline@master]

Hi there,

I'm trying to run the Jenkinsfile from https://github.com/mozilla/kuma/blob/master/Jenkinsfile.

Questions

Logs with library

library 'github.com/mozmeao/jenkins-pipeline@master'
$ docker run -v $(pwd):/workspace marcellodesales/jenkinsfile-runner
Started
Running in Durability level: PERFORMANCE_OPTIMIZED
[Pipeline] library
[Pipeline] End of Pipeline
ERROR: No library named github.com/mozmeao/jenkins-pipeline found
Finished: FAILURE

Logs with @Library

$ docker run -v $(pwd):/workspace marcellodesales/jenkinsfile-runner
Started
Running in Durability level: PERFORMANCE_OPTIMIZED
ERROR: Could not find any definition of libraries [github.com/mozmeao/jenkins-pipeline@master]
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: Loading libraries failed

1 error

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:559)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:520)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:319)
	at hudson.model.ResourceController.execute(ResourceController.java:97)
	at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE

Vanilla Docker packaging downloads latest plugins instead of ones defined by payload-dependencies

Currently Docker packaging just explodes, because it pulls latest plugin dependencies instead of ones defined in https://github.com/jenkinsci/jenkinsfile-runner/blob/master/payload-dependencies/pom.xml .

I might need to integrate https://github.com/jenkinsci/custom-war-packager or https://github.com/jenkinsci/plugin-installation-manager-tool into the build process to retrieve a proper set of dependencies

Add support of Job Names with folders

#203 added support of arbitrary Job names, but it is not possible to set a folder using the current approach. It would be great to add support of nested paths like folder1/folder2/job1 so that users of Jenkinsfile Runner can emulate standard Jenkins structures more easily.

CC @rinckm @alxsap

Is it possible to actual run the docker steps?

Building docker image for runtime null
[Pipeline] sh
[job] Running shell script
+ docker build -t tests:null -f Dockerfile.tests .
/tmp/jenkinsTests.tmp/jenkins8996889882339540707test/workspace/job@tmp/durable-57fedee8/script.sh: 2: /tmp/jenkinsTests.tmp/jenkins8996889882339540707test/workspace/job@tmp/durable-57fedee8/script.sh: docker: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Tests Execution)
...
...
...
ERROR: script returned exit code 127
Finished: FAILURE

Create a Java/Maven demo based on the Vanilla package

Since we have jenkins4eval/jenkinsfile-runner up and running again, it would be great to have a small demo demonstrating the Docker image override

  • - Demo includes Dockerfile which is based on the jenkins4eval/jenkinsfile-runner image
  • - Dockerfile install Maven (JDK is already bundled)
  • - There is a Jenkinsfile which checks out a small hello-world sample repo and builds/tests it inside Jenkinsfile Runner
  • - There is a README file in the demo which describes how to build/run the demos

Scripts not permitted to use staticMethod

Hello,
I got error during running pipeline
Scripts not permitted to use staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods
How to fix this issue fr jenkinsfile-runer ?

Build instructions?

Nice tool, it's really helped me troubleshoot my Jenkinsfile. However, there is a noticeable lack of build instructions in the repo. Lot's of stuff on how to use it but nothing on how to build it. I was able to successfully reverse engineer the build process on my mac from the Dockerfile but a build or installation section in the documentation would be nice.

startup speed option

I run the below command and it's take ~11 sec till I see the output from the pipeline.

How can I reduce the start time of jenkinfile-runner ?

/users/kube/jenkins-runner -w /users/kube/jenkins -p /users/kube/jenkins_home/plugins -f myJenkinsfile

"Error deleting stale/expired events from EventHistoryStore" in pipeline

Hi,

I've seen this error in a pipeline run by Jenkinsfile runner. I suspect this might be a race condition between Jenkinsfile runner deleting /tmp/jenkinsfileRunner.tmp and the sse-gateway-plugin deleting /tmp/jenkinsfileRunner.tmp/jfr2051626485582005540.run/logs/sse-events.

I'm not sure if this issue is correct in this repo, and sadly I also can't reproduce the issue. Please close the issue if it is not relevant.

Stacktrace:

Finished: FAILURE
 762.648 [id=39]	SEVERE	o.j.p.s.EventHistoryStore$DeleteStaleHistoryTask#run: Error deleting stale/expired events from EventHistoryStore.
java.nio.file.NoSuchFileException: /tmp/jenkinsfileRunner.tmp/jfr2051626485582005540.run/logs/sse-events
	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.newDirectoryStream(UnixFileSystemProvider.java:427)
	at java.nio.file.Files.newDirectoryStream(Files.java:457)
	at org.jenkinsci.plugins.ssegateway.EventHistoryStore.deleteAllFilesInDir(EventHistoryStore.java:215)
	at org.jenkinsci.plugins.ssegateway.EventHistoryStore.deleteStaleHistory(EventHistoryStore.java:192)
	at org.jenkinsci.plugins.ssegateway.EventHistoryStore$DeleteStaleHistoryTask.run(EventHistoryStore.java:268)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)

Jenkinsfile Runner should fail immediately when running on an unsupported Jenkins version

jenkins.version in pom.xml actually defines the minimum supported Jenkins version. But this version is not really checked anywhere, and JFR run may fail randomly. It would be nice to verify the Jenkins version before staring execution.

Jenkins WAR file includes the Jenkins core version in its properties: https://github.com/jenkinsci/jenkins/blob/master/core/src/main/java/jenkins/model/Jenkins.java#L5057-L5066 . The code can be copied from there

It is a follow-up to #170

Doesn't support @Library annotations

When running a jenkinsfile that has a @Library declaration, after configuring global plugins and declaring a global Pipeline library in the Jenkins instance, jenkinsfile-runner fails:

WorkflowScript: 2: unable to resolve class Library ,  unable to find class for annotation
 @ line 2, column 1.
   @Library('libname') _

To reproduce:

  1. Follow the setup instructions as per README.md and install plugins
  2. in the Jenkins instance localhost:8080 go to Manage Jenkins select Global configuration
  3. configure the Global Pipeline Library section to be able to pull down from an SCM a library repository
  4. Add an @Library annotion to a jenkinsfile that you with to run pointing to the global library you defined above
  5. Run jenkinsfile-runner -w $JENKINS_HOME -p $JENKINS_HOME -f path/to/Jenkinsfile_with_anotation

Pipelines may fail if parameter has empty value

Problem

Jenkinsfile Runner has a --arg option to pass parameters to the pipeline. The value of a parameter may be a zero-length string:

/app/bin/jenkinsfile-runner --arg PARAM1='' ...

In such case the respective StringParameterValue in the job's ParametersAction will have its value set to null. This is different from the behavior of a pipeline job with parameters in a classical Jenkins, where the value is never null but a zero-length string if no default value has been defined via the respective StringParameterDefinition). As a consequence pipelines running successfully in a classical Jenkins may break when executed with Jenkinsfile Runner, for instance in hudson.model.StringParameterValue#buildEnvironment()

How to reproduce

Create a directory testcase with a Jenkinsfile having the following contents:

node {
    sh '''\
        #!/bin/bash
        if [ -n "$PARAM1" ]; then
            echo "PARAM1 is set"
        else
            echo "PARAM1 is not set"
        fi
    '''.stripIndent()
}

Change into directory testcase and run the pipeline via Jenkinsfile Runner:

docker run -it \
    -v "$PWD/Jenkinsfile":/workspace/Jenkinsfile \
    -e "JAVA_OPTS=-Dhudson.model.ParametersAction.keepUndefinedParameters=true" \
    ppiper/jenkinsfile-runner \
        --arg PARAM1=

Remark 1: Setting the system property hudson.model.ParametersAction.keepUndefinedParameters=true is required to include all parameters into the environment of pipeline steps like it is done with classical pipeline jobs having expected parameters declared via ParametersDefinitionProperty.

Remark 2: The Docker image ppiper/jenkinsfile-runner may be replaced by your own Jenkinsfile Runner image. You may also run the testcase without Docker if you have a Jenkinsfile Runner available on your machine.

Output:

Started
Running in Durability level: PERFORMANCE_OPTIMIZED
[Pipeline] Start of Pipeline
[Pipeline] node
2019-09-18 08:24:45.970+0000 [id=59]	WARNING	o.j.plugins.workflow.cps.DSL#invokeStep: Error storing the arguments for step: sh
java.lang.IllegalArgumentException: Null value not allowed as an environment variable: PARAM1
	at hudson.EnvVars.put(EnvVars.java:378)
	at hudson.model.StringParameterValue.buildEnvironment(StringParameterValue.java:59)
	at hudson.model.ParametersAction.buildEnvironment(ParametersAction.java:145)
	at hudson.model.Run.getEnvironment(Run.java:2383)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.getEnvironment(WorkflowRun.java:471)
	at org.jenkinsci.plugins.workflow.support.DefaultStepContext.get(DefaultStepContext.java:72)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:242)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
	at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1278)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1172)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:84)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:87)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:78)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:186)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:370)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:93)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:282)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:270)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:66)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
	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)
Running on Jenkins in /tmp/jenkinsfileRunner.tmp/jfr5831395852522203582.run/workspace/job
[Pipeline] {
[Pipeline] sh
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.lang.IllegalArgumentException: Null value not allowed as an environment variable: PARAM1
	at hudson.EnvVars.put(EnvVars.java:378)
	at hudson.model.StringParameterValue.buildEnvironment(StringParameterValue.java:59)
	at hudson.model.ParametersAction.buildEnvironment(ParametersAction.java:145)
	at hudson.model.Run.getEnvironment(Run.java:2383)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.getEnvironment(WorkflowRun.java:471)
	at org.jenkinsci.plugins.workflow.support.DefaultStepContext.get(DefaultStepContext.java:72)
	at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:264)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:263)
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:179)
	at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
	at groovy.lang.MetaClassImpl.invokeMethodOnGroovyObject(MetaClassImpl.java:1278)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1172)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
	at WorkflowScript.run(WorkflowScript:4)
	at ___cps.transform___(Native Method)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:84)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:83)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:87)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:113)
	at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:78)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
	at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
	at com.cloudbees.groovy.cps.Next.step(Next.java:83)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
	at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:129)
	at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:268)
	at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:186)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:370)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:93)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:282)
	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:270)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:66)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
	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)
Finished: FAILURE

Expected result:

Started
Running in Durability level: PERFORMANCE_OPTIMIZED
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /build
[Pipeline] {
[Pipeline] sh
PARAM1 is not set
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Analysis

The Jenkinsfile Runner uses args4j to parse its arguments (see the Bootstrap class).

For the --arg option args4j uses the MapOptionHandler, which converts empty string values to null.

The Jenkinsfile Runner's Runner class passes the parsed key-value pairs from the --arg options - with the value possibly being null - as StringParameterValues in a ParametersAction into the pipeline job.

Proposed Solution

The postConstruct() method of Jenkinsfile Runner's Bootstrap class should replace all null values in map this.workflowParameters by zero-length strings.

beta9 NoClassDefFoundError: org/jenkinsci/plugins/workflow/job/properties/DurabilityHintJobProperty

Hello, I started jenkinsfile-runner (expanded war, empty plugins dir, https://repo.jenkins-ci.org/releases/io/jenkins/jenkinsfile-runner/jenkinsfile-runner/1.0-beta-9/jenkinsfile-runner-1.0-beta-9-app.zip). I would suggest to create FAT JAR instead (dir containing individual JARs and shell script).

bin/jenkinsfile-runner -w ../jenkins-war-2.7.3 -f /mnt/c/tmp/jenkins/ -p ~ -a "param1=Hello"  -a "param2=value2"
2019-10-04 10:39:47.195+0000 [id=1]     SEVERE  h.i.i.InstallUncaughtExceptionHandler$DefaultUncaughtExceptionHandler#uncaughtException: A thread (main/1) died unexpectedly due to an uncaught exception, this may leave your Jenkins in a bad way and is usually indicative of a bug in the code.
java.lang.ClassNotFoundException: org.jenkinsci.plugins.workflow.job.properties.DurabilityHintJobProperty
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Caused: java.lang.NoClassDefFoundError: org/jenkinsci/plugins/workflow/job/properties/DurabilityHintJobProperty
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at io.jenkins.jenkinsfile.runner.JenkinsfileRunnerLauncher.launch(JenkinsfileRunnerLauncher.java:133)
        at io.jenkins.jenkinsfile.runner.App.run(App.java:14)
        at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.run(Bootstrap.java:206)
        at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.main(Bootstrap.java:94)

Error running jenkinsfile-runner on Windows

After running
jenkinsfile-runner.bat -w C:\Temp\jenkins -p C:\Temp\jenkins_home\plugins -f C:\project
no plugin in C:\Temp\jenkins_home\plugins is loaded.

There is a long list of errors similar to this:

2019-12-18 21:00:33.499+0000 [id=32] SEVERE jenkins.InitReactorRunner$1#onTaskFailed: Failed Loading plugin Trilead API Plugin v1.0.5 (trilead-api) java.io.IOException: Trilead API Plugin version 1.0.5 failed to load.
- You must update Jenkins from version 2.176.2 to version 2.184 or later to run this plugin. at hudson.PluginWrapper.resolvePluginDependencies(PluginWrapper.java:868) at hudson.PluginManager$2$1$1.run(PluginManager.java:544) at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:169) at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296) at jenkins.model.Jenkins$5.runTask(Jenkins.java:1095) at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214) at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

Jenkins Telemetry prints warnings on JFR startup

$ java -jar /c/Users/Oleg/Documents/jenkins/jfr/jenkinsfile-runner/app/target/jenkinsfile-runner-standalone.jar --plugins ../../vanilla-package/target/plugins/ --jenkins-war ../../vanilla-package/target/war/ --runWorkspace work -f .
2019-10-09 14:59:24.300+0000 [id=32]    WARNING hudson.util.PluginServletFilter#addFilter: Filter instance is registered too early: jenkins.telemetry.impl.UserLanguages$AcceptLanguageFilter@2a
java.lang.Exception
        at hudson.util.PluginServletFilter.addFilter(PluginServletFilter.java:108)
        at jenkins.telemetry.impl.UserLanguages.setUpFilter(UserLanguages.java:102)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104)
        at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175)
        at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
        at jenkins.model.Jenkins$5.runTask(Jenkins.java:1095)
        at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
        at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
        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)
2019-10-09 15:00:14.564+0000 [id=1]     WARNING j.branch.WorkspaceLocatorImpl#getWorkspaceRoot: JENKINS-2111 path sanitization ineffective when using legacy Workspace Root Directory ‘/c/Users/Oleg/Documents/jenkins/jfr/jenkinsfile-runner/demo/declarative-pipeline/work’; switch to ‘${JENKINS_HOME}/workspace/${ITEM_FULL_NAME}’ as in JENKINS-8446 / JENKINS-21942

Add a Jenkins CLI command mode

It would be great if Jenkinsfile Runner supported a mode for calling Jenkins CLI commands against itself. It might be useful to get a list of installed plugins (list-plugins) or, for example, to generate a support bundle using https://github.com/jenkinsci/support-core-plugin and so on.

E.g.:

docker run -i --rm -v $(pwd)/Jenkinsfile:/workspace/Jenkinsfile jenkins4eval/jenkinsfile-runner --cli list-plugins

Ideally it would be great to just support interactive mode like Jenkins SSH CLI does.

docker run -i --rm -v $(pwd)/Jenkinsfile:/workspace/Jenkinsfile jenkins4eval/jenkinsfile-runner --cli

It would require a new engine to be added on the top of Jenkinsfile Engine, but it would be useful

NoClassDefFoundError: org/jenkinsci/plugins/workflow/job/properties/DurabilityHintJobProperty

When building with today's default plugins a NoClassDefFoundError occurs when running the Jenkinsfile shown in the usage section of the README.

This must be somehow related to default plugins, because when running with the default plugins from 2018-02-25 the pipeline runs successfully. (I extracted the plugins from a docker image I built two weeks ago, schnatterer/jenkinsfile-runner:1.0-SNAPSHOT-2.108)

jenkinsfile-runner built from git commit ae14205
Tested with jenkins 2.108.

Stacktrace:

   6.054 [id=1] SEVERE  h.i.i.InstallUncaughtExceptionHandler$DefaultUncaughtExceptionHandler#uncaughtException: A thread (main/1) died unexpectedly due to an uncaught exception, this may leave your Jenkins in a bad way and is usually indicative of a bug in the code.
java.lang.ClassNotFoundException: org.jenkinsci.plugins.workflow.job.properties.DurabilityHintJobProperty
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Caused: java.lang.NoClassDefFoundError: org/jenkinsci/plugins/workflow/job/properties/DurabilityHintJobProperty
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at io.jenkins.jenkinsfile.runner.App$1.evaluate(App.java:28)
        at io.jenkins.jenkinsfile.runner.JenkinsfileRunnerRule$2.evaluate(JenkinsfileRunnerRule.java:127)
        at io.jenkins.jenkinsfile.runner.App.run(App.java:32)
        at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.run(Bootstrap.java:61)
        at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.main(Bootstrap.java:51)

-jv (--jenkins-verion) flag crashing CLI

Repro'd with example jenkinsfile from Readme. Freshly installed, OSX Catalina; brand new Java & JDK as well. Let me know if I can be of more help tracking this down!

% java -jar jenkinsfile-runner-1.0-beta-11.jar -p ./plugins.txt
No explicit version has been selected, using latest LTS
Running pipeline on jenkins 2.204.5
Downloading jenkins 2.204.5...
^C%                                                                                                                     
 % java -jar jenkinsfile-runner-1.0-beta-11.jar -p ./plugins.txt -jv 2.204.5
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1770)
	at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
	at java.base/java.util.regex.Matcher.<init>(Matcher.java:253)
	at java.base/java.util.regex.Pattern.matcher(Pattern.java:1135)
	at hudson.util.VersionNumber.parseVersion(VersionNumber.java:377)
	at hudson.util.VersionNumber.<init>(VersionNumber.java:368)
	at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.isVersionSupported(Bootstrap.java:228)
	at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.postConstruct(Bootstrap.java:144)
	at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.main(Bootstrap.java:121)
% java -jar jenkinsfile-runner-1.0-beta-11.jar -p ./plugins.txt -jv "2.204.5"
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.regex.Matcher.getTextLength(Matcher.java:1770)
	at java.base/java.util.regex.Matcher.reset(Matcher.java:416)
	at java.base/java.util.regex.Matcher.<init>(Matcher.java:253)
	at java.base/java.util.regex.Pattern.matcher(Pattern.java:1135)
	at hudson.util.VersionNumber.parseVersion(VersionNumber.java:377)
	at hudson.util.VersionNumber.<init>(VersionNumber.java:368)
	at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.isVersionSupported(Bootstrap.java:228)
	at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.postConstruct(Bootstrap.java:144)
	at io.jenkins.jenkinsfile.runner.bootstrap.Bootstrap.main(Bootstrap.java:121)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.