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

Add an interactive CLI mode (--cli argument) #207

Merged
merged 1 commit into from Nov 6, 2019

Conversation

literalplus
Copy link
Contributor

@literalplus literalplus commented Oct 20, 2019

Ellipsis

As suggested by #178, this PR adds a way to access the Jenkins CLI from jenkinsfile-runner.

Technical Overview

To support the new mode of execution, a new JenkinsLauncher superclass has been extracted from the existing JenkinsfileRunnerLauncher, to abstract Jenkins setup capabilities. A new subclass CliLauncher has been added that provides a loop forwarding commands via CliCommand.clone(). App now has a switch on the new Bootstrap.cliOnly flag, and decides which implementation to use.

This flag can be set via --cli or -c, and additionally via a FORCE_JENKINS_CLI environment variable. The latter is mainly intended for use with Docker (otherwise we'd need a custom entrypoint script or a separate Dockerfile just for CLI).

Usage

$ docker run --rm -it -e FORCE_JENKINS_CLI=true jenkinsfile-runner:dev
Connected to Jenkins!
Type 'help' for a list of available commands, or 'exit' to quit.
 > show-plugins
No such command, try 'help'.
 > list-plugins
ace-editor                         JavaScript GUI Lib: ACE Editor bundle plugin                     1.1
...
workflow-multibranch               Pipeline: Multibranch                                            2.21
 > who-am-i
Authenticated as: anonymous
Authorities:
  anonymous
 > bye
$ app/target/appassembler/bin/jenkinsfile-runner -w /tmp/jenkins -p /tmp/jhome/plugins --cli
...

I hope this is somewhat similar to what was meant with "new engine" in #178.

Fixes #178

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a bootstrap would be a cleaner approach IMHO. Jenkins official Docker images do that, and we may need it here to provide better compatibility with classic images. E.g. JAVA_OPTS, DEBUG, JENKINS_OPTS have a real use-case in JFR.

But it is fine to do it as a follow-up

}
}

private List<String> findArgsFromLineParts(String[] commandLineParts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be generalized in JenkinsLauncher

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move it there, but I don't see how this internal utility method belongs there semantically - the only other existing implementation doesn't do command-line parsing and this use-case seems very specific to this one mode.

DOCKER.md Outdated Show resolved Hide resolved
@literalplus
Copy link
Contributor Author

literalplus commented Oct 20, 2019

Thanks for the review @oleg-nenashev!

With "bootstrap" you mean the Docker image and providing a docker-entrypoint.sh script that removes the need to handle the env var in the application itself, right? If so, that makes sense & I can do that. Can you think of anything else such a script should do besides JENKINS_OPTS and DEBUG? Otherwise, can you please elaborate?

I just noticed that the integration tests are failing due to an IllegalAccessError which sounds...interesting, I'll take a look at it & push the solution together with the two resolved discussions if I find one.

Update: The IllegalAccessError seems unrelated, also occurs on master. The tests also fail there and in other PRs. Haven't yet figured out which of the tests is failing and it is related to my changes (I find the shunit output a little unintuitive to read)

Update: The failing test is test_pipeline_execution_hangs in tests-negative-scenarios.sh. I'm not sure why this fails.

Update: Failures seem to be random. I first thought it was caused by my earlier PR, but running it a second time with the master before that also failed it. Possibly related: Error response from daemon: conflict: unable to delete 044193f3a355 (cannot be forced) - image is being used by running container 42ad8f3a0ce7

Update: I got the tests to pass locally by re-trying in a loop: while ! bash ./tests-negative-scenarios.sh; do; echo "try again"; done: I guess we could re-try them on the CI multiple times as well, but this seems more like a hack than a solution.

@literalplus literalplus force-pushed the 178/cli-mode branch 2 times, most recently from b3c6aee to c7325a0 Compare October 21, 2019 01:16
@oleg-nenashev
Copy link
Member

With "bootstrap" you mean the Docker image and providing a docker-entrypoint.sh script that removes the need to handle the env var in the application itself, right?

Yes

Update: The failing test is test_pipeline_execution_hangs in tests-negative-scenarios.sh. I'm not sure why this fails.

Just ignore it for now, please. CI is still not very stable. I will test it manually before merging

@oleg-nenashev
Copy link
Member

Retriggering CI

@literalplus
Copy link
Contributor Author

merge conflicts resolved

literalplus added a commit to literalplus/jenkinsfile-runner that referenced this pull request Oct 25, 2019
This allows users to pass "cli" or "run" as Docker CMD to easily
switch modes without having to set environment variables. Also provides
the DEBUG environment variable that used to be provided by the
launcher script (which is no longer used as of this).

Also removes the FORCE_JENKINS_CLI environment variables as it's no
longer necessary.

as per jenkinsci#207 (comment)
@literalplus
Copy link
Contributor Author

In the meantime, another flag with the -c shorthand was added (for setting the cause), so I have removed that alias.

literalplus added a commit to literalplus/jenkinsfile-runner that referenced this pull request Oct 26, 2019
This allows users to pass "cli" or "run" as Docker CMD to easily
switch modes without having to set environment variables. Also provides
the DEBUG environment variable that used to be provided by the
launcher script (which is no longer used as of this).

Also removes the FORCE_JENKINS_CLI environment variables as it's no
longer necessary.

as per jenkinsci#207 (comment)
@oleg-nenashev
Copy link
Member

oleg-nenashev commented Oct 27, 2019 via email

@oleg-nenashev oleg-nenashev changed the title Add a basic interactive CLI mode Add an interactive CLI mode (--cli argument) Nov 6, 2019
Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it manually, and it works like a charm. Thanks!
I will go ahead and merge it without #213, we can integrate it in a follow-up

@oleg-nenashev oleg-nenashev merged commit 1310748 into jenkinsci:master Nov 6, 2019
@oleg-nenashev oleg-nenashev added the enhancement New feature or request label Nov 6, 2019
@literalplus literalplus deleted the 178/cli-mode branch November 6, 2019 20:39
literalplus added a commit to literalplus/jenkinsfile-runner that referenced this pull request Nov 10, 2019
This allows users to pass "cli" or "run" as Docker CMD to easily
switch modes without having to set environment variables. Also provides
the DEBUG environment variable to the non-dev Dockerfile.

Removes the FORCE_JENKINS_CLI environment variables as it's no
longer necessary.

as per jenkinsci#207 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a Jenkins CLI command mode
2 participants