Automatically execute Sphinx on Python script using Jenkins - python

I have been trying to create a Jenkins job that automatically executes a python script and launch its documentation via Sphinx.
The execution part works well but I'm not able to do the Sphinx part. My first idea was to create an 'Execute Windows Script bash' step inside the Jenkins job with make html command after going to the right directory with cd. But I keep on getting this error:
make is not recognized as an internal or external command
Same idea works when I do it from the CMD tool.
I already added the PATH variable in Jenkins settings with System32 folder.
System Information:
OS: Windows
Arch: x64

I figured out, I just had to put the following inside my Windows Shell Job:
call "Path\To\make.bat"

Related

Python was not found error when runnig code

After a few routine windows updates, I started getting this error when I was running python code in VSCode.
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases.
I got told to first check PATH and to untoggle Python in App Execution Aliasies. I figured that python was already added to the PATH (I had just checked the box when downloading) and that when I untoggle Python in App Execution Aliasies I get another error
'python3' is not recognized as an internal or external command, operable program or batch file.
So I'm essentially stuck between two different errors and a correct PATH and the only times when I can run a code is when I run it from the default Python IDE that comes in the download package.
Anyone know how to fix this?
PS. when I download Python from Windows Store, it works but I don't know how to use pip with it to install external packages.
Below is the pic of my PATH.
Please reinstall python. When you install python, there will be a prompt in the lower left corner to automatically add it to the environment variable. Please check it.
At the same time, please select the correct Python interpreter in vscode.
You can refer to docs for more information.

How to execute Kaggle Api commands on windows system?

I'm referring to https://github.com/Kaggle/kaggle-api
I tried executing the sample commands listed on the page in windows CMD and Python's IDLE. Not sure where it should be executed or how can I go to Kaggle CLI?
Eg. command: kaggle datasets list -s demographics
Windows CMD says: 'kaggle' is not recognized as an internal or external command,
operable program or batch file.
Assuming the Kaggle API has been successfully installed using pip and the python install location along with the location of the Scripts\ folder have been added into the PATH; the execution of kaggle directly within Windows command prompt (CMD) should be able.
In order to ensure Python and the folder Scripts\ have been added into the PATH execute the command WHERE python3 succeeding WHERE kaggle.
If any of the two commands above produce an equivalent output of INFO: Could not find files for the given pattern(s) manually modify the PATH using the directions in Excursus: Setting environment variables to add both python install location and location of the Scripts\ folder.
You can run Bash commands on Windows using the Bash shell, which is a little tricky to launch the first time. You can find instructions on how to do that here: https://www.windowscentral.com/how-install-bash-shell-command-line-windows-10
Hope that helps! :)

Can't run python scripts in Jenkins

I have been using Jenkins for a few years and recently bought a new Windows 10 PC. I installed Jenkins 2.89.2, Visual Studio 2017 and Python 3.6 and copied several Jenkins jobs from my previous Windows 7 PC.
The problem that I encountered was that all the python scripts in the free-style Jenkins jobs now do nothing.
I have similar command-line batch files which run these python scripts which work just fine in a command window on the new PC.
I have also checked the file associations with ftype, and ended up changing it:
ftype Python.File
Python.File="D:\Python36_64\python.exe" "%L" %*
My work-around is like this:
Example line which worked under Windows 7:
CreateBuildNumber.py <= uses PATH to find this file, then file associations to run python
Replacement line need to work under Windows 10:
python .\Scripts\CreateBuildNumber.py <= uses PATH to find python.
How can I avoid explicit paths in my scripts?
Update:
D:\project>assoc | findstr -i python
.py=Python.File
.pyc=Python.CompiledFile
.pyd=Python.Extension
.pyo=Python.CompiledFile
.pyw=Python.NoConFile
.pyz=Python.ArchiveFile
.pyzw=Python.NoConArchiveFile
echo %PATH%
D:\Python36_64;D:\Python36_64\Scripts;.\Scripts;"C:\Program Files\CppCheck";C:\windows\system32
Further Info
I removed .\Scripts from the %PATH% and re-ran the job, having also moved demo.py into .\Scripts, now instead of doing nothing there is the error:
'demo.py' is not recognized as an internal or external command, operable program or batch file.
This means that Windows IS looking for and finding python scripts, but is failing to execute them. Why would windows not take the next step and use file associations to find an executable program to run, taking the file as a parameter?
Update:
Now everything works as it should and I don't know why.
I recently started using a different job on Jenkins that I had neither run nor touched for over two years and that one just worked without modification. I have since gone back over the job in question and reverted all the changes and this one works as well.
My guess is that Windows 10 has been patched.
The fact that "demo.py" gives the message '...is not recognized as an internal or external command' doesn't convince me that your script is recognized as executable. If I type 'turkey.abc' into a command prompt window I get the same error, and I don't have a tool for executing '.abc' files.
I see two possibilities here:
1) In batch scripts, executable extensions sometimes must appear in an environment variable called PATHEXT.
In the Jenkins batch script, add a "set" command near the top of the script to dump the environment variables for your running script into your Jenkins build log (you can remove the set command after this is debugged). Run the build. Look not only for the definition of PATH, but also at PATHEXT. Is ".py" one of the extensions listed there?
I have experienced this problem with Perl scripts. However, I'm wimping out on claiming this definitely since in testing on my Windows 10 home PC I am successfully executing .py scripts even without it being in PATHEXT, so it's something to try but it may not be this.
2) Another possibility is that the environment in which your service is running is different than the environment you get when you open a command prompt on your desktop (because the Jenkins service runs as a different user than the one you log in as.)
Adding "set" to your Jenkins batch commands will help debugging this too, since it will show you the environment your Jenkins script is running in. Then you can examine PATH to see if your script folder is being found.
It is also possible that the file associations for Python were installed for your user only, not for all users (i.e., in HKEY_CURRENT_USER in the registry instead of HKEY_LOCAL_MACHINE). That is harder to dump into your Jenkins log - the 'reg' command would do it, but it will take you a number of tries to get everything you need. You might be able to figure it out by just examining the registry. Search for ".py" - if it occurs in HKEY_LOCAL_MACHINE that is not it; if it occurs in HKEY_CURRENT_USER that is at least part of the problem.
I don't know if this will fix your issue but you shouldn't have a relative path in your PATH environment variable.
Can you try again after having removing .\Scripts from the PATH variable? (don't forget to open a fresh new terminal do get the new %PATH% value)
The problem is that your PATH variable doesn't include the paths of you python scripts. You need the full path of the Scripts directory. Not the relative path .\Scripts.

Get logs of what jenkins is doing

I am completely new at jenkins. I installed the windows package and tried it out but I am a little lost.
Here is my issue. I basically need jenkins to run a python script located on my computer. It's a scipt that has 1 line
print("hello World")
I created a new build setup with the following under the Build Environment
"Execute windows batch command"
cd "C:\perforce\projects\DEV\E9318_SuperNova\P22_module_split_up\Ref\Tools\"
"C:\perforce\projects\DEV\E9318_SuperNova\P22_module_split_up\Ref\Tools\test.py"
The console output from the build
Building in workspace C:\Program Files (x86)\Jenkins\workspace\E9318_SuperNova-P22_Compensator_FPGA_PSA
[E9318_SuperNova-P22_Compensator_FPGA_PSA] $ cmd /c call C:\windows\TEMP\jenkins7605841087640242580.bat
C:\Program Files (x86)\Jenkins\workspace\E9318_SuperNova-P22_Compensator_FPGA_PSA>cd "C:\perforce\projects\DEV\E9318_SuperNova\P22_module_split_up\Ref\Tools\"
C:\perforce\projects\DEV\E9318_SuperNova\P22_module_split_up\Ref\Tools>"C:\perforce\projects\DEV\E9318_SuperNova\P22_module_split_up\Ref\Tools\test.py"
C:\perforce\projects\DEV\E9318_SuperNova\P22_module_split_up\Ref\Tools>exit 103
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
I am not sure what I am doing wrong. Any help would be highly appreciated,
Thanks,
Amish
*.py files don't seem to be executable directly (as invoked from a shell)
Change the second line of your script with :
"C:\path\to\python.exe" "C:\perforce\projects\DEV\E9318_SuperNova\P22_module_split_up\Ref\Tools\test.py"
Anyway, this form field is expecting the path to a script that makes the build and runs the tests.
I will also refer to
How to set the PATH environment variable in Jenkins configuration on Windows? as a possible solution. After I added the python executable path to the node's path, I could call my script using
python.exe "C:\perforce\projects\DEV\E9318_SuperNova\P22_module_split_up\Ref\Tools\test.py"

Python console not launching properly from command line

I seem to have problem launching python from command line. I tried various things with no success.
Problem: When trying to run python from the command line, there is no response i.e. I do not get message about 'command not found' and console does not launch. Only option to open python console is to run C:\Python34\python.exe directly. Running using python command does not work even when in the python directory but python.exe launches. Issue with the launching this way is that python console is launched in new window. This whole problem is present only on one machine while on my other machine I am able to run python correctly and console launches in the command prompt window from which the python command was executed.
PATH is correctly set to
C:\Python34\;C:\Python34\Scripts;...
and where python correctly returns C:\Python34\python.exe. I verified that running other commands imported through PATH (such as javac) run correctly.
Things I tried:
Completely re-installing python both with x86 and x64 python installations with no success.
Copy installation from my second machine and manually set the path variables - again no success.
Can anyone hint how to resolve this behavior?
(Additional info: Win 8.1 x64, python 3.4.2)
Issue resolved. Since no feasible solution was found in 2 days, I decided to wipe all keys containing 'python' from registry as well as some files that were not parts of other programs. This resolved the issue after re-installing python.
If anyone finds the true cause of this misbehavior and other - less brutal - solution, please write it here for future reference.
Recent Python installer has option to add PATH.
If you didn't use it, you can register directory where python.exe is to PATH environment variable.
But I prefer py launcher. It may be installed via Python 3.3 or 3.4.
With it, you can start Python via py or py -3.4.
See https://docs.python.org/3/using/windows.html#python-launcher-for-windows

Categories

Resources