문서의 이전 판입니다!
기본 Ant 태스크에 공통 옵션을 적용해두고 호출할 수 있는 속임수 기법이 있다. Ant 태스크와 동일한 이름으로 함수를 만들고 거기서 ant.태스크이름으로 명시적으로 Ant 태스크를 호출하면서 기본값을 지정해주면 된다. exec 참조.
exec(executable: '명령어', failonerror: true) { arg value: '명령행 인자 1' arg value: '명령행 인자 2' arg line: '명령행인자를 한 줄로 쭉..' env key: '환경변수이름', value: '환경변수값' }
faileonerror : 오류 발생시 빌드 즉시 실패dir : 명령을 실행한 디렉토리 명시resultproperty : faileonerror=false일 때 리턴값을 저장할 프라퍼티 이름문자열 하나에 명령과 인자를 모두 넣은 상태에서 failonerror를 항상 true로 한 기본 exec를 만들어 두고 호출 할 수 있다.
def exec(command, dir = '.') { def splittedCommand = command.split(' ') def executable = splittedCommand[0] ant.exec(executable: executable, failonerror: true, dir: dir) { if (splittedCommand.size() > 1) { splittedCommand[1..-1].each { arg value: it } } } } target(hello: 'world') { // ant.exec보다 로컬에 선언한 함수 exec가 우선된다. exec('cmd /c dir') }
target(remotels: 'Remote list files') { ant.sshexec(host: '호스트네임/IP주소', username: '계정명', password: '비밀번호', failonerror: true, trust: true, command: 'ls /etc') }
target(remotels: 'Remote list files') { ant.sshexec(host: '호스트네임/IP주소', username: '계정명', keyfile: '${user.home}/.ssh/id_dsa', passphrase: '패스프레이즈', failonerror: true, trust: true, command: 'ls /etc') }
sudo -S는 stdin으로 부터 비밀번호를 입력받도록 해주는 옵션이다.inputstring (문자열), inputproperty (지정된 프라퍼티에 있는 값), input (파일의 내용) 등의 옵션은 stdin으로 보낼 내용을 적는 방법들이다.usepty는 가상의 TTY를 생성해준다(ssh -t). Ant 1.8.3 이상 버전이 필요하다.sudo 사용이 가능해진다.target(remotels: 'Remote list files') { ant.sshexec(host: '호스트네임/IP주소', username: '계정명', keyfile: '${user.home}/.ssh/id_dsa', passphrase: '패스프레이즈', failonerror: true, trust: true, inputstring: 'sudo비밀번호\n', // \n로 엔터치게 해준다. usepty: true, command: 'sudo -S ls /var/log/httpd') }
command: 'cmd1; cmd2; cmd3; …' : 여러 명령어를 실행한다.command: 'cmd1 & cmd2 & cmd3 & …' : 여러 명령어를 실행하되 앞의 명령이 성공해야만(and 조건) 다음 명령을 실행한다.commandResource: '명령이 줄 단위로 들어있는 파일명' : 파일에서 명령을 읽어서 실행한다.commandResource를 사용하면 inputstring등의 stdin으로 지정한 입력이 명령 실행시마다 반복 입력된다.sshexec와 동일하다.