

Amazon CodeCatalyst는 더 이상 신규 고객에게 공개되지 않습니다. 기존 고객은 정상적으로 서비스를 계속 이용할 수 있습니다. 자세한 내용은 [CodeCatalyst에서 마이그레이션하는 방법](migration.md) 단원을 참조하십시오.

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 변수의 예
<a name="workflows-working-with-variables-ex"></a>

다음 예시에서는 워크플로 정의 파일에서 변수를 정의하고 참조하는 방법을 보여줍니다.

변수에 대한 자세한 내용은 [워크플로에서 변수 사용](workflows-working-with-variables.md) 섹션을 참조하세요.

**Topics**
+ [예시: Inputs 속성을 사용하여 변수 정의](#workflows-working-with-variables-ex-define-inputs)
+ [예시: Steps 속성을 사용하여 변수 정의](#workflows-working-with-variables-ex-define-steps)
+ [예시: Outputs 속성을 사용하여 변수 내보내기](#workflows-working-with-variables-ex-export-outputs)
+ [예시: 동일한 작업에 정의된 변수 참조](#workflows-working-with-variables-ex-refer-current)
+ [예시: 다른 작업에 정의된 변수 참조](#workflows-working-with-variables-ex-refer-other)
+ [예시: 보안 암호 참조](#workflows-working-with-variables-ex-refer-secret)

## 예시: Inputs 속성을 사용하여 변수 정의
<a name="workflows-working-with-variables-ex-define-inputs"></a>

다음 예시에서는 `Inputs` 섹션에서 두 개의 변수인 `VAR1` 및 `VAR2`를 정의하는 방법을 보여줍니다.

```
Actions:
  Build:
    Identifier: aws/build@v1
    Inputs:
      Variables:
      - Name: VAR1
        Value: "My variable 1"
      - Name: VAR2
        Value: "My variable 2"
```

## 예시: Steps 속성을 사용하여 변수 정의
<a name="workflows-working-with-variables-ex-define-steps"></a>

다음 예시에서는 `Steps` 섹션에서 `DATE` 변수를 명시적으로 정의하는 방법을 보여줍니다.

```
Actions:
  Build:
    Identifier: aws/build@v1
    Configuration:    
      Steps:
        - Run: DATE=$(date +%m-%d-%y)
```

## 예시: Outputs 속성을 사용하여 변수 내보내기
<a name="workflows-working-with-variables-ex-export-outputs"></a>

다음 예시에서는 두 개의 변수인 `REPOSITORY-URI` 및 `TIMESTAMP`를 정의하고 `Outputs` 섹션을 사용하여 내보내는 방법을 보여줍니다.

```
Actions:
  Build:
    Identifier: aws/build@v1
    Inputs:
      Variables:
        - Name: REPOSITORY-URI
          Value: 111122223333.dkr.ecr.us-east-2.amazonaws.com/codecatalyst-ecs-image-repo
    Configuration:
      Steps:
        - Run: TIMESTAMP=$(date +%m-%d-%y-%H-%m-%s) 
    Outputs:
      Variables:
        - REPOSITORY-URI
        - TIMESTAMP
```

## 예시: 동일한 작업에 정의된 변수 참조
<a name="workflows-working-with-variables-ex-refer-current"></a>

다음 예시에서는 `MyBuildAction`에서 `VAR1` 변수를 지정한 다음 `$VAR1`를 사용하여 동일한 작업에서 변수를 참조하는 방법을 보여줍니다.

```
Actions:
  MyBuildAction:
    Identifier: aws/build@v1
    Inputs:
      Variables:
        - Name: VAR1
          Value: my-value
    Configuration:
      Steps:
        - Run: $VAR1
```

## 예시: 다른 작업에 정의된 변수 참조
<a name="workflows-working-with-variables-ex-refer-other"></a>

다음 예시에서는 `BuildActionA`에서 `TIMESTAMP` 변수를 지정하고 `Outputs` 속성을 사용하여 내보낸 다음 `${BuildActionA.TIMESTAMP}`를 사용하여 `BuildActionB`에서 참조하는 방법을 보여줍니다.

```
Actions:
  BuildActionA:
    Identifier: aws/build@v1
    Configuration:    
      Steps:
        - Run: TIMESTAMP=$(date +%m-%d-%y-%H-%m-%s) 
    Outputs:
      Variables:
        - TIMESTAMP
  BuildActionB:
    Identifier: aws/build@v1
    Configuration:
      Steps:
        - Run: docker build -t my-ecr-repo/image-repo:latest .      
        - Run: docker tag my-ecr-repo/image-repo:${BuildActionA.TIMESTAMP}
        
        # Specifying just '$TIMESTAMP' here will not work 
        # because TIMESTAMP is not a variable 
        # in the BuildActionB action.
```

## 예시: 보안 암호 참조
<a name="workflows-working-with-variables-ex-refer-secret"></a>

다음 예시에서는 `my-password` 보안 암호를 참조하는 방법을 보여줍니다. `my-password`는 보안 암호의 키입니다. 이 보안 암호의 키와 해당 암호 값은 워크플로 정의 파일에서 사용하기 전에 CodeCatalyst 콘솔의 **보안 암호** 페이지에서 지정해야 합니다. 자세한 내용은 [보안 암호를 사용하여 데이터 마스킹](workflows-secrets.md) 섹션을 참조하세요.

```
Actions:
  BuildActionA:
    Identifier: aws/build@v1
    Configuration:    
      Steps:
        - Run: curl -u LiJuan:${Secrets.my-password} https://example.com
```