Post-build arguments to batch script fails to convert build parameter - batch-file

I'm using TFS 2013 and am building an Azure Cloud Service project that I want to package with Nuget so that I can publish to Octopus Deploy. I can't use octopack, because at the moment this is not supported. I'm trying to pass TFS parameters into a post-build batch script so that I can run nuget with -version parameters (which should change with each build).
The problem I'm having is that the batch script does not recognise the TFS build parameters. for example, in the script I want to pass an argument version $(TeamProject)-1.0.0$(Rev:.r), that would give the script the version to set in the package name.
The full nuget package call in the script is:
%nugetPath% push %packagePath%\Veedyo.%version%.nupkg
Passing this into the post-build script path works:
$/Application1/MAIN/Source/.NET/Application1.Package/package.cmd
This is because the source control path is translated into an actual path just after the build completes (and I can see the real path in the log).
However, the Post-build script arguments property in the build, doesn't convert this "$(TeamProject)"-1.0.0"$(Rev:.r)" to the desired value. this leads to an error executing the batch script:
Exception Message: TF270015: 'package.cmd' returned an unexpected exit code. Expected '0'; actual '1'. See the build logs for more details
So, does anyone have any idea how to convert add build parameter to the post-build script arguments property?

These macros are not available when you run the script. You can use one the the TF_BUILD environment variables listed here.
Probably, you are looking for TF_BUILD_BUILDNUMBER, or maybe you have to extract the data you are looking for; in this latter case Powershell can be simpler to use than cmd.exe interpreter.

Related

The term 'behave' is not recognized as the name of a cmdlet, function

I have Python 3.10.7 with the follwing packgaes installed using pip install in command line:
behave 1.2.6
selenium 4.4.3
These have also been added to the packagelist of the project using the project config in pycharm
Also behave is in the systme path as well along with python.
I am trying to use the behave command but I am getting the following error:
behave : The term 'behave' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ behave features\myfeaturefile.feature
Following is my project directory:
Following is my project in pycharm:
I need help in fixing this problem as I am new to this tool. Thanks
First check if you have behave and python in the path variables.
Check if you can execute the below command
C:\demo>behave -h
If this does not return a list of help commands associated with behave, this means that behave is not in the path variables
Alternatively, you can check it via cmd using the "PATH" command. This will show you all the entries in the system path
C:\demo>PATH
PATH=C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Program Files\AdoptOpenJDK\jdk-11.0.11.9-hotspot\bin...
If behave or python are not in the path variables, you can set them using
set PATH=%PATH%;c:\PATH_TO_BEHAVE
NOTE: Setting path using cmd is only valid till the time the cmd window is open. Once you close it, the path variable will be rest to original values.
Behave, along with a few other .exe files is sitting in the:
C:\Users\chauhany\AppData\Roaming\Python\Python310\Scripts
As per your instructions #Manish Agarwal, I added the C:\Users\chauhany\AppData\Roaming\Python to the PATH from the command line and re-started the machine. But it didn't help. I then moved the behave.exe from the above location to my python 3.10 directory which is sitting in C:\Program Files\Python310 and python is in the system path, and restarted my machine again.
I then deleted and recreated my project with the new feature file (same directory structure).
If I now run the same command, that is, features\myfeaturefile.feature from
C:\Users\chauhany\PycharmProjects\martechBehaveProject>
I get a FileNotFound error
So I went to the folder where the file is actually sitting that is:
C:\Users\chauhany\PycharmProjects\martechBehaveProject\features\steps> and then re-ran the command and it worked.
I was under the impression that if you have just one feature file you don't have to specify the actual feature file and it can be run from anywhere in your project i.e., from any location which certainly is not correct.

KNIME Command Line Execution - ClassNotFoundException

I'd like to schedule a KNIME workflow. The workflow does its job very good as long as I start it from the KNIME GUI application. When I execute the same workflow via command line, java complains that com.microsoft.sqlserver.jdbc.SQLServerDriver
could not be found (ClassNotFoundException).
I invoke it via:
"D:\Progamme\KNIME\knime.exe" -nosplash -application -consoleLog org.knime.product.KNIME_BATCH_APPLICATION -preferences="absolutepathto\preferences.epf" -workflowDir="absolutepathto\workflow"
Since the error message signals missing content in the java CLASSPATH I also tried to add the parameters
-vmargs -classpath .;"absolutepathto/sqljdbc42.jar"
But still I earn a java slap, pointing to the same error...
I also tried to run the command from within the knime.exe's directory and I also tried to add the JAR file to Preferences -> Java -> Build Path -> Classpath Variable / User Libraries (referenced via the -preference argument). But that had no effect.
Did anybody face the same problems? Maybe with other third party JARs?
It is all about a Database connector that is configured like this:
Does the integrated security maybe force a misleading error?
System spec: KNIME 3.2.2 on Windows Server 2008 R2
Update - extract from preferences file
/configuration/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
/configuration/org.eclipse.ui.ide/MAX_RECENT_WORKSPACES=10
/configuration/org.eclipse.ui.ide/RECENT_WORKSPACES=<list of some workspaces>
/configuration/org.eclipse.ui.ide/RECENT_WORKSPACES_PROTOCOL=3
/configuration/org.eclipse.ui.ide/SHOW_RECENT_WORKSPACES=false
/configuration/org.eclipse.ui.ide/SHOW_WORKSPACE_SELECTION_DIALOG=true
Is there maybe a problem due to the fact that it is a shared KNIME instance among several users and the command line execution does not know which workspace has to be chosen? Is the workspace somehow needed and why?
Partial Solution:
I finally managed it but I don't know exactly why it works now. What I did was to load a fresh portable version of KNIME and ran the same commands only changing the executable path to the new portable version. Before that I started the portable version once to set the workspace directory and register the database driver in preferences dialog and .ini file, nothing else, same configuration so far as the shared KNIME instance. What I am really wondering abpout is that from now on the commands are also working with the shared KNIME instance. I really don't know what caused the change that let KNIME find the driver class.
Info
Because I encountered a few more problems within shared environment in KNIME command line mode, that led to undeterministic execution results, I wrote a little .NET library. This gives me more flexibility/control over the workflow execution (which returncodes and error messages occured and so on). You can find it here if you're interested: KnimeNet
I took a very minimal approach:
cd "C:\Program Files\KNIME"
.\knime -nosplash -noexit -consoleLog -reset -application org.knime.product.KNIME_BATCH_APPLICATION -workflowFile="D:\Work\Knime Workflows\Output\CMD_Test.knwf" -preferences="D:\Work\Knime Workflows\Output\CMD_Test.epf"

Jenkins parameter is getting replaced by a white space

I have a parameterized build (copied from an existing job) in Jenkins. While building, my parameter is getting replaced by a white space. Here I am sharing what I have.
Parameter Name: BuildDate (I tried using %% and ${} but no luck)
Windows batch command:
copy \\Network_drive\dir1\dir2\dir3%BuildDate%\filename*.zip .
Output from Jenkins console:
c:\jenkins\workspace\my_build_job_name>copy \\Network_drive\dir1\dir2\dir3\ \filename*.zip .
\\Network_drive\dir1\dir2\dir3\ \filename*.zip
The system cannot find the path specified. 0 file(s) copied
c:\jenkins\workspace\my_build_job_name>exit 1
Build step 'Execute Windows batch command' marked build as failure
Notifying upstream projects of job completion Finished: FAILURE*
Note: We have a Windows/Linux mixed environment. Whenever we want to run shell scripts, we use Cygwin, batch should directly run.
Finally it turned out that one of the parameters was not populating due to hitting "rebuild last". Re-running the whole pipeline did it work. I still wonder why it was not populating but its all hood now!!!

manage Jenkins build status

I'd like to run batch using jenkins. And the status of build depends of number of files created in a specific folder. My question is how could I manage Jenkins build status depending of number of files created?
You can execute a shell script to count the files and return 1, if the count isn't expected.
Another way would be to use the Text-finder Plugin searching for a pattern in the console log.
Groovy Postbuild Plugin is another alternative:
buildUnstable() - sets the build result to UNSTABLE.
If you like to use the CLI you can use the following command:
java -jar jenkins-cli.jar -s http://...:8080/ set-build-result
Sets the result of the current build. Works only if invoked from within a build.

Error when execute within a TFS build definition

When I tried to call command-line to get latest update for my TFS mapped folder
TF get /recursive
The call complete successfully from the run window of Windows 7.
However, when I put the call into a .bat file and run it via InvokeProcess within a build definition (guide to do that), it failed.
The message is as below.
Unable to determine the workspace. You may be able to correct this by
running 'tf workspaces /collection:TeamProjectCollectionUrl'
What happens? How can I get around with that?
The reason this is happening is because when you run the command locally, the folder you're downloading is mapped to a workspace. When you execute the command in your build, it's running under the build service account, which doesn't have a workspace mapped for the folder you're specifying.
You shouldn't need to use the tf get command as part of your build. When you configure your build, you can specify which folders should be mapped in the workspace on the "Source Settings" tab. The build process will handle making sure the contents of the folders you map in your workspace are present automatically.
The cause for my issue is that the build agent execute my .bat file under a different Windows account which is something like NTSERVICE; when I run it directly, my TFS login account was used (which was previously remembered in Windows 7 Credential Manager)
So the solution is to put in the login name and password as TF get /login:SomeTFSUsername,SomePassword (see more here)

Resources