forked from hashicorp/python-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_stage_example.py
More file actions
60 lines (46 loc) · 1.42 KB
/
Copy pathtask_stage_example.py
File metadata and controls
60 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Example usage of TaskStages API
Demonstrates:
- Read a task stage
- List task stages for a run
- Override a task stage
"""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
from pytfe import TFEClient, TFEConfig
def main():
client = TFEClient(TFEConfig.from_env())
task_stage_id = os.getenv("TFE_TASK_STAGE_ID")
run_id = os.getenv("TFE_RUN_ID")
if not task_stage_id or not run_id:
print("Please set TFE_TASK_STAGE_ID and TFE_RUN_ID")
return
print("=== TaskStages Example ===")
# READ
print("\nReading task stage...")
try:
stage = client.task_stages.read(task_stage_id)
print(f"ID: {stage.id}")
print(f"Stage: {stage.stage}")
print(f"Status: {stage.status}")
print(f"Run: {stage.run.id if stage.run else None}")
except Exception as e:
print(f"Read failed: {e}")
# LIST
print("\nListing task stages...")
try:
stages = list(client.task_stages.list(run_id))
for s in stages:
print(f"{s.id} - {s.status}")
except Exception as e:
print(f"List failed: {e}")
# OVERRIDE
print("\nOverriding task stage...")
try:
client.task_stages.override(task_stage_id, comment="Approved")
print("Override successful")
except Exception as e:
print(f"Override failed: {e}")
if __name__ == "__main__":
main()