반응형

Jenkins Logo

안녕하세요.

즐거운 우리집 (https://joyfulhome.tistory.com/) 입니다.

 

얼마전 지인으로 부터 젠킨스에 대해서 문의가 들어왔습니다.

그래서 오늘은 간만에 젠킨스(Jenkins) 에 대해서 다시 알아보도록 하시죠.

 

이전에도 몇 번 젠킨스에 대한 사용법을 공유 드렸으나 정말 젠킨스는 훌륭한 프로그램이죠 ㅎ

컴퓨터에서 하는 단순한 실행 등을 정의해서 저장하면

사용자는 간단히 실행 버튼만 누르면 그 정의된 내용이 실행되니 말이죠.

 

더군다가 이걸 스케쥴을 만들어 일정 시간 간격으로 자동으로 실행을 할 수 있다니 말이죠 ^^

 

오늘은 이 젠킨스에서 실행시 Sting 파라미터(String Parameter)를 주고 사용할 수 있는 방법에 대해서 알아보도록 할께요.

그럼 자~ 함께 공부해 보시죠~ ^^

 

반응형

 

젠킨스에서 스트링 파라미터 사용하는 방법 (How to use string parameters in Jenkins)

01. 구성 > General > 이 빌드는 매개변수가 있습니다 > 매개변수 추가 > String Parameter

     String Parameter 를 사용하기 위하여 해당 job 의 구성 설정에서 General 에 있는

     '이 빌드는 매개변수가 있습니다.' 를 선택합니다.

     역서 많은 옵션들이 나오는데 우리는 문자열을 사용할 것이라 'String Parameter' 를 선택합니다.

     이 파라미터에 대한 설명은 다음을 참고하세요.

Parameters allow you to prompt users for one or more inputs that will be passed into a build. For example, you might have a project that runs tests on demand by allowing users to upload a zip file with binaries to be tested. This could be done by adding a File Parameter here.
Or you might have a project that releases some software, and you want users to enter release notes that will be uploaded along with the software. This could be done by adding a Multi-line String Parameter here.Each parameter has a Name and some sort of Value , depending on the parameter type. These name-value pairs will be exported as environment variables when the build starts, allowing subsequent parts of the build configuration (such as build steps) to access those values, e.g. by using the ${PARAMETER_NAME} syntax (or %PARAMETER_NAME% on Windows).
This also implies that each parameter defined here should have a unique Name .

When a project is parameterized, the usual Build Now link will be replaced with a Build with Parameters link, where users will be prompted to specify values for each of the defined parameters. If they choose not to enter anything, the build will start with the default value for each parameter.
If a build is started automatically, for example if started by an SCM trigger, the default values for each parameter will be used.
When a parameterized build is in the queue, attempting to start another build of the same project will only succeed if the parameter values are different, or if the Execute concurrent builds if necessary option is enabled.
See the Parameterized Builds documentation for more information about this feature.

 

 

02. 매개변수 명 : 이름으로 사용할 것 / Default Value : 파라미터 Value

     사용할 파라미터 이름과 기본 value 를 입력합니다. (뒤에서 다시 설명드리겠지만, 이 value 는 실행시 간단하게 변경 가능합니다.)

     매개변수 : 파라미터 명

     Default Value : 파라미터 value

 

 

03. 사용할 파라미터 위치에 % 와 파라미터 명 입력

     실행명령어 뒤에 사용할 파라미터명을 입력해 줍니다.

     실행시 사용하기 위해 입력한 파라미터 value 를 전달해 주기 위해서 해당 파라미터 앞뒤에 퍼센트(%) 를 붙여줍니다.

 

 

04. 실행시 파라미터 노출

     해당 job 을 실행하면 바로 실행이 되지 않고 변수로 입력한 파라미터 이름과 초기 Value 값이 노출됩니다.

     우리는 필요시 이 Value 를 수정해도 되고, 기본값을 그대로 사용해도 됩니다.

     하단의 '빌드하기' 버튼을 클릭합니다.

 

 

05. 실행결과

     저는 git 을 이용하여 필요한 Branch Name 으로 pull 하는 명령어를 테스트로 해 보았습니다.

    git pull origin %BranchName% 을 실행문으로 주었지만, 

    Default Value 로 입력한 값으로 자동으로 변환되어

    git pull origin master 로 들어가네요. ^^

 

 

실행시 value 값이 계속 바뀌는 빌드라면 이렇게 String Parameter 로 받아서 실행시 

사용자가 수정할 수 있게 해주면 쉽게 사용할 수 있습니다.

 

궁금하신 사항은 언제든지 질문주세요 ^^

그럼 오늘도 즐거운 하루 되세요~ 

 

반응형