Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
one step for #163 (jenkins for linux)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Aug 19, 2018
1 parent 67389ce commit 2e3df8f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .local.jenkins.lin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ python:

# The test happens in a virtual environment not with the original distribution.
virtualenv:
- path: {{ospathjoin(root_path, pickname("%NAME_JENKINS%", project_name + "_%VERSION%_%DIST%_%NAME%"), "_venv")}}
- path: {{ospathjoin(root_path, pickname("$NAME_JENKINS", project_name + "_$VERSION_$DIST_$NAME"), "_venv")}}

# Dependencies to install.
install:
Expand Down
21 changes: 20 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def is_local():
"copy27", "copy_dist", "local_pypi", "notebook", "publish", "publish_doc",
"register", "unittests", "unittests_LONG", "unittests_SKIP", "unittests_GUI",
"run27", "sdist", "setupdep", "test_local_pypi", "upload_docs", "setup_hook",
"copy_sphinx", "write_version", "lab", "history", "run_pylint"}:
"copy_sphinx", "write_version", "lab", "history", "run_pylint", "jenkins"}:
if cname in sys.argv:
try:
import_pyquickhelper()
Expand Down Expand Up @@ -190,6 +190,25 @@ def write_version():
"69193a28-dc79-4a24-98ed-aedf441a8249", "'_UT_37_std' in outfile"),
github_owner=github_owner)

if "jenkins" in sys.argv:
# python setup.py jenkins <user> <password> /var/lib/jenkins/workspace
pos = sys.argv["jenkins"]
user = sys.argv[pos+1]
password = sys.argv[pos+2]
if len(sys.argv) > pos+3:
location = sys.argv[pos+3]
else:
location = "/var/lib/jenkins/workspace"
from pyquickhelper.jenkinshelper import JenkinsExt, setup_jenkins_server_yml, default_jenkins_jobs
modules = default_jenkins_jobs()
key = "Python%d%d" % sys.version_info[:2]
engines = {key: os.path.absname(os.path.dirname(sys.executable))}
js = JenkinsExt('http://localhost:8080/', user,
password, engines=engines)
setup_jenkins_server_yml(js, github="sdpython", modules=modules, fLOG=print, overwrite=True,
delete_first=False, location="")
r = True

if not r and not ({"bdist_msi", "sdist",
"bdist_wheel", "publish", "publish_doc", "register",
"upload_docs", "bdist_wininst", "build_ext"} & set(sys.argv)):
Expand Down
8 changes: 5 additions & 3 deletions src/pyquickhelper/jenkinshelper/jenkins_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,14 @@ def setup_jenkins_server_yml(js, github="sdpython", modules=None,
from pyquickhelper.jenkinshelper import JenkinsExt, setup_jenkins_server_yml, default_jenkins_jobs, default_engines
js = JenkinsExt('http://localhost:8080/', None, None)
user = "<user>"
password = "<password>"
modules = default_jenkins_jobs()
engines = default_engines()
js = JenkinsExt('http://localhost:8080/', user, password, engines=engines)
setup_jenkins_server_yml(js, github="sdpython", modules=modules, fLOG=print,
overwrite = True, delete_first=True, engines=engines,
location = "d:\\\\jenkins\\\\pymy")
overwrite=True, delete_first=False,
location="d:\\\\jenkins\\\\pymy")
See `.local.jenkins.win.yml <https://github.com/sdpython/pyquickhelper/blob/master/.local.jenkins.win.yml>`_
(Windows) or
Expand Down
15 changes: 10 additions & 5 deletions src/pyquickhelper/jenkinshelper/jenkins_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from ..pycode.windows_scripts import windows_jenkins_27_conda, windows_jenkins_27_def
from ..pycode.build_helper import private_script_replacements
from .jenkins_exceptions import JenkinsExtException, JenkinsJobException
from .jenkins_server_template import _config_job, _trigger_up, _trigger_time, _git_repo, _task_batch
from .jenkins_server_template import _config_job, _trigger_up, _trigger_time, _git_repo, _task_batch_win, _task_batch_lin
from .jenkins_server_template import _trigger_startup, _publishers, _file_creation, _wipe_repo, _artifacts
from .yaml_helper import enumerate_processed_yml
from .jenkins_helper import jenkins_final_postprocessing, get_platform
Expand Down Expand Up @@ -96,7 +96,7 @@ class JenkinsExt(jenkins.Jenkins):
Some useful :epkg:`Jenkins` extensions:
* `Credentials Plugin <https://wiki.jenkins-ci.org/display/JENKINS/Credentials+Plugin>`_
* `Extrea Column Plugin <https://wiki.jenkins-ci.org/display/JENKINS/Extra+Columns+Plugin>`_
* `Extra Column Plugin <https://wiki.jenkins-ci.org/display/JENKINS/Extra+Columns+Plugin>`_
* `Git Client Plugin <https://wiki.jenkins-ci.org/display/JENKINS/Git+Client+Plugin>`_
* `GitHub Client Plugin <https://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin>`_
* `GitLab Client Plugin <https://wiki.jenkins-ci.org/display/JENKINS/GitLab+Plugin>`_
Expand All @@ -112,7 +112,8 @@ class JenkinsExt(jenkins.Jenkins):
_trigger_time = _trigger_time
_trigger_startup = _trigger_startup
_git_repo = _git_repo
_task_batch = _task_batch
_task_batch_win = _task_batch_win
_task_batch_lin = _task_batch_lin
_publishers = _publishers
_wipe_repo = _wipe_repo
_artifacts = _artifacts
Expand Down Expand Up @@ -773,8 +774,12 @@ def create_job_template(self, name, git_repo, credentials="", upstreams=None, sc

# scripts
# tasks is XML, we need to encode s into XML format
tasks = before + [JenkinsExt._task_batch.replace(
"__SCRIPT__", escape(s)) for s in script_mod]
if self.platform.startswith("win"):
scr = JenkinsExt._task_batch_win
else:
scr = JenkinsExt._task_batch_lin
tasks = before + [scr.replace("__SCRIPT__", escape(s))
for s in script_mod]

# location
if location is not None and "<--" in location:
Expand Down
9 changes: 8 additions & 1 deletion src/pyquickhelper/jenkinshelper/jenkins_server_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,20 @@
"""

#: for the script
_task_batch = """
_task_batch_win = """
<hudson.tasks.BatchFile>
<command>__SCRIPT__
</command>
</hudson.tasks.BatchFile>
"""

_task_batch_lin = """
<hudson.tasks.Shell>
<command>__SCRIPT__
</command>
</hudson.tasks.Shell>
"""

#: mails
_publishers = """
<hudson.tasks.Mailer plugin="mailer">
Expand Down
2 changes: 1 addition & 1 deletion src/pyquickhelper/jenkinshelper/yaml_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def ospathjoinp(*l, **kwargs):
addition = "set current={0}\\%NAME_JENKINS%".format(
context["root_path"])
else:
addition = "export current={0}/%NAME_JENKINS%".format(
addition = "export current={0}/$NAME_JENKINS".format(
context["root_path"])
content = "automatedsetup:\n - {0}\n{1}".format(addition, content)

Expand Down

0 comments on commit 2e3df8f

Please sign in to comment.