[Jenkins] Jenkins CLI 사용

ITWeb/개발일반 2016. 6. 30. 20:05

aws 를 이용하다 보니 배포를 터미널에서 해야할 일이 종종 있습니다.

그래서 기록해 봅니다.


Jenkins에서 제공하는 CLI 기능을 이용합니다.

보통 Jenkins 를 설치 하시면 admin 으로 로그인 하셔서 Jenkins 관리로 들어 갑니다.

들어 가면, 바로 Jenkins CLI 메뉴가 눈에 들어 옵니다.


[SSH Public Key 등록]

jenkins user 설정 에서 ssh key 등록을 하셔야 합니다.


[Jenkins CLI 링크]

http://localhost:8080/jenkins/cli/


[Jenkins 기본 배포]

$ java -jar jenkins-cli.jar -s http://localhost:8080/jenkins/ build ${JOB_NAME} -s -v --username ${LOGIN_ID} --password ${LOGIN_PASSWORD}

- ${JOB_NAME} 은 처음에 item 만들때 작성하신 이름입니다. (jenkins view에 나오는 목록의 이름)



[Jenkins 기본 배포 + 파라미터 설정]

$ java -jar jenkins-cli.jar -s http://localhost:8080/jenkins/ build ${JOB_NAME} -s -v -p ${PARAM_NAME}="${PARMA_VALUE}" --username ${LOGIN_ID} --password ${LOGIN_PASSWORD}


[jenkins-cli.jar 위치]

jenkins 설치한 위치에서 webapps/jenkins/WEB-INF 아래 위치해 있습니다.


링크를 클릭하면 아래와 같은 화면을 보실 수 있습니다.


[Jenkins CLI 화면]

You can access various features in Jenkins through a command-line tool. See the Wiki for more details of this feature.To get started, download jenkins-cli.jar, and run it as follows:

java -jar jenkins-cli.jar -s http://52.196.187.249:8181/jenkins/ help

Available Commands

add-job-to-viewAdds jobs to view.
buildBuilds a job, and optionally waits until its completion.
cancel-quiet-downCancel the effect of the "quiet-down" command.
clear-queueClears the build queue.
connect-nodeReconnect to a node(s)
consoleRetrieves console output of a build.
copy-jobCopies a job.
create-credentials-by-xmlCreate Credential by XML
create-credentials-domain-by-xmlCreate Credentials Domain by XML
create-jobCreates a new job by reading stdin as a configuration XML file.
create-nodeCreates a new node by reading stdin as a XML configuration.
create-viewCreates a new view by reading stdin as a XML configuration.
delete-buildsDeletes build record(s).
delete-credentialsDelete a Credential
delete-credentials-domainDelete a Credentials Domain
delete-jobDeletes job(s).
delete-nodeDeletes node(s)
delete-viewDeletes view(s).
disable-jobDisables a job.
disconnect-nodeDisconnects from a node.
enable-jobEnables a job.
get-credentials-as-xmlGet a Credentials as XML (secrets redacted)
get-credentials-domain-as-xmlGet a Credentials Domain as XML
get-gradleList available gradle installations
get-jobDumps the job definition XML to stdout.
get-nodeDumps the node definition XML to stdout.
get-viewDumps the view definition XML to stdout.
groovyExecutes the specified Groovy script.
groovyshRuns an interactive groovy shell.
helpLists all the available commands or a detailed description of single command.
install-pluginInstalls a plugin either from a file, an URL, or from update center.
install-toolPerforms automatic tool installation, and print its location to stdout. Can be only called from inside a build.
keep-buildMark the build to keep the build forever.
list-changesDumps the changelog for the specified build(s).
list-credentialsLists the Credentials in a specific Store
list-credentials-context-resolversList Credentials Context Resolvers
list-credentials-providersList Credentials Providers
list-jobsLists all jobs in a specific view or item group.
list-pluginsOutputs a list of installed plugins.
loginSaves the current credential to allow future commands to run without explicit credential information.
logoutDeletes the credential stored with the login command.
mailReads stdin and sends that out as an e-mail.
offline-nodeStop using a node for performing builds temporarily, until the next "online-node" command.
online-nodeResume using a node for performing builds, to cancel out the earlier "offline-node" command.
quiet-downQuiet down Jenkins, in preparation for a restart. Don’t start any builds.
reload-configurationDiscard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk.
reload-jobReload job(s)
remove-job-from-viewRemoves jobs from view.
replay-pipelineReplay a Pipeline build with edited script taken from standard input
restartRestart Jenkins.
safe-restartSafely restart Jenkins.
safe-shutdownPuts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down Jenkins.
session-idOutputs the session ID, which changes every time Jenkins restarts.
set-build-descriptionSets the description of a build.
set-build-display-nameSets the displayName of a build.
set-build-parameterUpdate/set the build parameter of the current build in progress.
set-build-resultSets the result of the current build. Works only if invoked from within a build.
set-external-build-resultSet external monitor job result.
shutdownImmediately shuts down Jenkins server.
update-credentials-by-xmlUpdate Credentials by XML
update-credentials-domain-by-xmlUpdate Credentials Domain by XML
update-jobUpdates the job definition XML from stdin. The opposite of the get-job command.
update-nodeUpdates the node definition XML from stdin. The opposite of the get-node command.
update-viewUpdates the view definition XML from stdin. The opposite of the get-view command.
versionOutputs the current version.
wait-node-offlineWait for a node to become offline.
wait-node-onlineWait for a node to become online.
who-am-iReports your credential and permissions.


: