我有下面两个yaml模板
test-template.yml
jobs:
-job: Pytest
steps:
- task: UsepythonVersion
displayName: 'Pytest1'
inputs:
verion_secific: some_pthon_version
script: pytest -v tests -k "pretest_case1"
jobs:
-job: Pytest
steps:
- task: UsepythonVersion
displayName: 'Pytest2'
inputs:
verion_secific: some_pthon_version
script: pytest -v tests -k "postTest_case2"
字符串
Main.yaml
steps:
- task: Bash@3
displayName: 'Before inserted step'
inputs:
targetType: inline
script: echo "This step is before the inserted step."
stages
- stage:test_int1
pool:
vmImage : ubuntu
jobs:
- template: test-template.yml<Pytest1 >
- stage:test_int2
pool:
vmImage : ubuntu
jobs:
- template: test-template.yml<Pytest2 >
型
如何从test-template.yml中分别调用Main.yaml中“Pytest 1”和“Pytest 2”?
我尝试了下面的脚本不使用python
parameters:
- name: jobName
type: string
- name: proj_name
type: string
jobs:
- job: ${{ parameters.jobName }}
steps:
- script: |
# Set the test_case_name based on jobName
if [ "${{ parameters.jobName }}" = "Pytest2" ]; then
test_case_name="not Pytest2"
else
test_case_name="Pytest2"
fi
# Run pytest with the computed test_case_name
pytest -v tests -k "$test_case_name"
# Capture the exit code of pytest
exit_code=$?
# Handle the exit_code as needed (e.g., print a message or exit with an error code)
if [ $exit_code -ne 0 ]; then
echo "Tests failed"
exit 1
fi
型
但看起来下面的部分没有评估if条件,即使值是“Pytest 2”
if [ "${{ parameters.jobName }}" = "Pytest2" ]
型
有正确的方法吗?
1条答案
按热度按时间ecfsfe2w1#
看下面的代码工作
个字符