Jenkins API Examples with ‘curl’ command

curl example
* curl -X GET –user allessunjoo.park:TOKEN_EXAMPLE_VALUE http://cerberus.lge.com/jenkins/job/starfish-jcl4v-verify-m16p3/api/json?pretty=true

Advertisements

Jenkins bulid get an error message: java.io.IOException: error=7, Argument list too long

What’s  occured?

When Jenkins triggered a  build job defines as “Free-Style Project”, a build failed with this error message


[starfish-verify-drd] $ /bin/bash /tmp/jenkins8550337881106633559.sh

FATAL: command execution failed

java.io.IOException: error=7, Argument list too long

	at java.lang.UNIXProcess.forkAndExec(Native Method)

	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)

	at java.lang.ProcessImpl.start(ProcessImpl.java:134)

	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)

Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to swfarm-gateuobld17

		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1737)

		at hudson.remoting.UserResponse.retrieve(UserRequest.java:313)

		at hudson.remoting.Channel.call(Channel.java:952)

		at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1052)

		at hudson.Launcher$ProcStarter.start(Launcher.java:449)

		at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:109)

		at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)

		at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)

		at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)

		at hudson.model.Build$BuildExecution.build(Build.java:206)

		at hudson.model.Build$BuildExecution.doRun(Build.java:163)

		at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)

		at hudson.model.Run.execute(Run.java:1727)

		at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)

		at hudson.model.ResourceController.execute(ResourceController.java:97)

		at hudson.model.Executor.run(Executor.java:429)

Caused: java.io.IOException: Cannot run program "/bin/bash" (in directory "/vol/users/gatekeeper.tvsw/cerberus_root/starfish-verify-drd"): error=7, Argument list too long

	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)

Cause 

  • One argument must not be longer than MAX_ARG_STRLEN (131072 bytes)

Reference

Vimscript: Sample codes for command completions

Sample Code

 

" Sample functions {{{
function! Varg(foo)
    "echom a:0
    "echom a:1
    "echom a:2
    echom a:foo
    let cmd_str = "git ls-remote ssh://wall.lge.com/" . a:foo . " | head -n 10"
    let r = system(cmd_str)
    !echo r
endfunction

function! Vargs2(foo, ...)
    "echom a:foo
    "echom a:0
    " echom a:1
    echo a:0
endfunction

function! Assign(foo)
    " let a:foo = "Nope"
    let foo_tmp = a:foo
    let foo_tmp = "Yep"
    echom a:foo
    endfunction
" }}}

com! -complete=custom,ListUserstwo -nargs=1 Sunjoo2 call Varg("")
fun! ListUserstwo(A,L,P)
    return "starfish/build-starfish\nwebos-pro/meta-lg-webos"
endfun

Sunjoo2: Command name

call Varg(“”): Vim command triggered when calling a command

ListUserstwo: Function that returns a list of strings for parameter completion

Define VIM shorcuts for ‘Tab’-related actions

Reference: https://superuser.com/a/622114

if has("gui_macvim")
" Press Ctrl-Tab to switch between open tabs (like browser tabs) to
" the right side. Ctrl-Shift-Tab goes the other way.
noremap  :tabnext
noremap  :tabprev

" New Tab
noremap  :tabnew
" Switch to specific tab numbers with Command-number
noremap  :tabn 1
noremap  :tabn 2
noremap  :tabn 3
noremap  :tabn 4
noremap  :tabn 5
noremap  :tabn 6
noremap  :tabn 7
noremap  :tabn 8
noremap  :tabn 9
" Command-0 goes to the last tab
noremap  :tablast
endif

Create a Self-Signed Certificate with one line openssl command

Codes


#!/bin/bash
openssl req -newkey rsa:4096 -nodes -sha256 \
-keyout certs/domain.key -x509 -days 365 \
-out certs/domain.crt \
-subj "/C=KR/ST=Seoul/L=Seongbuk/O=Korea University,\
Inc/CN=*.io/emailAddress=all4dich@gmail.com"

Files

  • certs/domain.key
    • Root CA Privat Key
  • certs/domain.crt
    • Self-Signed Certificate

How to view a certification file’s content on a shell

keytool -printcert -file certificate.pem

Example for Apache SSL configuration


SSLEngine on

SSLCertificateFile /home/sunjoo/work/docker_registry2/certs/domain.crt
SSLCertificateKeyFile /home/sunjoo/work/docker_registry2/certs/domain.key

Deploy a Docker registry with enabling ‘Secured’ and ‘Authenticated’

This page shows how you can create a self-signed certificate and authentications. With them, you can deploy a Docker registry with ‘secured’, ‘authenticated’, and externally accessible.

Steps

  1. Create a base directory for a Docker registry and move to it
    • mkdire ~/docker_registry
  2. Create a self-signed certificate for a registry
      • command
        • mkdir certs #Make a directory where you store certificate and key
        • openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key -x509 -days 365 -out certs/domain.crt -subj "/C=KR/ST=Seoul/L=Seongbuk/O=Korea University, Inc/CN=ie.korea.ac.kr/emailAddress=all4dich@gmail.com"
      • Change CN‘s value as a hostname that you want
  3. After creating them, copy ‘certs/domain.crt’ to a client host as /etc/docker/certs.d/HOST_NAME:PORT/ca.crt
  4. Create a basic authentication information
    • Command
      • docker run --entrypoint htpasswd registry:2 -Bbn john.doe john.password >> auth/htpasswd
  5. Start the docker registry
    • Command
      • REG_NAME="registry_auth"
        docker rm -f $REG_NAME
        docker run -d -p 5001:5001 --restart=always --name $REG_NAME \
        -v `pwd`/certs:/certs \
        -v `pwd`/auth:/auth \
        -v `pwd`/data_nontls:/var/lib/registry \
        -e REGISTRY_HTTP_ADDR="0.0.0.0:5001" \
        -e "REGISTRY_AUTH=htpasswd" \
        -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
        -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
        -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt\
        -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
        registry:2
    • REGISTRY_HTTP_TLS_CERTIFICATE and REGISTRY_HTTP_TLS_KEY use certificate and key file’s absolute path within the container
    • REGISTRY_HTTP_ADDR use IP and port number within the container
    • You can use ‘-p’ parameter to map a docker’s internal port as a host’s external port

Comments

  • If you want to restrict an access, you have to use ‘authentication mechanism’ with TLS-enabled Docker registry
    • TLS encrypt/decrypt data between a registry and Docker daemon, not restrict access itself
  • ‘insecured-repositories’ can be used for plain http and https protocol
  • You have to use a domain name on ‘CN=*’ when creating a self-signed certificate.

Reference

Common

Docker for Mac

Others

  • memo