Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CONF
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UvA
CONF
Commits
9b72148c
Commit
9b72148c
authored
Jun 09, 2020
by
Spiros Koulouzis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added environment
parent
ed587183
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
semaphore_helper.py
...hon-client-generated/semaphore_client/semaphore_helper.py
+25
-3
test_task.py
semaphore-python-client-generated/test/test_task.py
+3
-1
No files found.
semaphore-python-client-generated/semaphore_client/semaphore_helper.py
View file @
9b72148c
import
json
from
datetime
import
datetime
import
urllib3
from
semaphore_client
import
Configuration
,
ApiClient
,
api
,
ProjectRequest
,
Login
,
AccessKeyRequest
,
InventoryRequest
,
\
RepositoryRequest
,
TemplateRequest
,
Task
RepositoryRequest
,
TemplateRequest
,
Task
,
EnvironmentRequest
class
SemaphoreHelper
:
...
...
@@ -77,8 +78,12 @@ class SemaphoreHelper:
templates
=
self
.
project_api
.
project_project_id_templates_get
(
project_id
,
playbook_name
,
'asc'
)
return
self
.
find_template
(
templates
,
playbook_name
)
.
id
def
execute_task
(
self
,
project_id
,
template_id
,
playbook_name
):
task
=
Task
(
template_id
=
template_id
,
playbook
=
playbook_name
)
def
execute_task
(
self
,
project_id
,
template_id
,
playbook_name
,
environment_id
=
None
):
environment_name
=
None
if
environment_id
:
environment
=
self
.
find_environment
(
project_id
,
environment_id
=
environment_id
)
environment_name
=
environment
.
name
task
=
Task
(
template_id
=
template_id
,
playbook
=
playbook_name
,
environment
=
environment_name
)
self
.
project_api
.
project_project_id_tasks_post
(
task
,
project_id
)
tasks
=
self
.
project_api
.
project_project_id_tasks_get
(
project_id
)
return
self
.
find_latest_task
(
tasks
)
.
id
...
...
@@ -126,4 +131,21 @@ class SemaphoreHelper:
for
repo
in
repositories
:
if
repo
.
git_url
==
git_url
:
return
repo
return
None
def
create_environment
(
self
,
project_id
,
name
,
env_vars
):
vars
=
{
"ENV"
:
env_vars
}
vars_str
=
json
.
dumps
(
vars
)
environment_request
=
EnvironmentRequest
(
name
=
name
,
project_id
=
project_id
,
password
=
None
,
json
=
vars_str
)
self
.
project_api
.
project_project_id_environment_post
(
environment_request
,
project_id
)
environment
=
self
.
find_environment
(
project_id
,
name
,
vars_str
)
return
environment
.
id
def
find_environment
(
self
,
project_id
,
name
=
None
,
vars_str
=
None
,
environment_id
=
None
):
environments
=
self
.
project_api
.
project_project_id_environment_get
(
project_id
,
'db-deploy'
,
'desc'
)
for
environment
in
environments
:
if
environment_id
and
environment
.
id
==
environment_id
:
return
environment
if
environment
.
name
and
environment
.
name
==
name
and
environment
.
project_id
==
project_id
and
environment
.
json
==
vars_str
:
return
environment
return
None
\ No newline at end of file
semaphore-python-client-generated/test/test_task.py
View file @
9b72148c
...
...
@@ -60,7 +60,9 @@ class TestTask(unittest.TestCase):
repository_id
=
self
.
semaphore_helper
.
create_repository
(
self
.
project_name
,
project_id
,
key_id
,
self
.
git_url
)
template_id
=
self
.
semaphore_helper
.
create_template
(
project_id
,
key_id
,
inventory_id
,
repository_id
,
self
.
playbook_name
)
task_id
=
self
.
semaphore_helper
.
execute_task
(
project_id
,
template_id
,
self
.
playbook_name
)
env_vars
=
{
"SOME_VAR"
:
"the contents"
}
environment_id
=
self
.
semaphore_helper
.
create_environment
(
project_id
,
self
.
project_name
,
env_vars
)
task_id
=
self
.
semaphore_helper
.
execute_task
(
project_id
,
template_id
,
self
.
playbook_name
,
environment_id
=
environment_id
)
for
x
in
range
(
0
,
2
):
task
=
self
.
semaphore_helper
.
get_task
(
project_id
,
task_id
)
print
(
task
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment