i need to rename a file in database using sql script. The sql script must be executed from an ant script.How can this be done?
If ant can call executables then you could call the sqlcmd.exe utility - you can pass it a query as a string (using -Q) or you can tell it a file that contains your commands (using -i).
Related
My program generates SQL files. In IntelliJ IDEA, with my database connected, I can run a .sql file as documented here. However, it seems I cannot add a run configuration that performs that exact run for me. Is there a way?
I have a SQL Server Database Project in Visual Studio 2015. This project is being used by the CI/CD tool to publish to the target databases using msbuild with a SqlPublishTask and an associated publish profile.
The msbuild command looks something like:
"C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" "c:\pathto\MySqlProj\MySql.sqlproj" /t:Publish /p:SqlPublishProfilePath="c:\pathto\MySqlProj\MyProfile.publish.xml" /p:UpdateDatabase=True /p:PublishScriptFileName="MySqlProj.ssdt-artefact.sql" /m /nr:false
Any schema related changes are successfully published.
However, the pre-build sql script is not run. I can see this because old data that should be removed by the pre-build script is not. I have also tested the pre-build script separately and it works fine.
I have checked and the pre-build script has a Build Action of PreDeploy. The location of the pre-build script in the project is:
c:\pathto\MySqlProj\Scripts\Pre-Deploy\Script.PreDeployment.sql
Any idea why the pre-deploy script is not running?
Managed to solve this. From experimentation it looks like even though a pre-deployment script is created using the Pre-Deployment Script template this doesn't mark the file as being a pre-deployment script.
Instead, it appears that MSBuild is looking for a specific comment section at the start of the file in order to determine if it is a pre-deployment script:
/*
Pre-Deployment Script Template
--------------------------------------------------------------------------------------
This file contains SQL statements that will be executed before the build script.
Use SQLCMD syntax to include a file in the pre-deployment script.
Example: :r .\myfile.sql
Use SQLCMD syntax to reference a variable in the pre-deployment script.
Example: :setvar TableName MyTable
SELECT * FROM [$(TableName)]
--------------------------------------------------------------------------------------
*/
In my case, those comments had been removed. Adding them back resulted in the script being run. The same is true for post-deployment scripts.
I have a very simple script which spits out environment variables like this:
Write-Host "SYSTEM_TEAMPROJECT: $ENV:SYSTEM_TEAMPROJECT"
My build has one step, the PowerShell task. The task script filename is set to the path to the script in TFSVC e.g. $/Main/BuildProcessTemplates/AllProps.ps1.
When I queue a new build it fails reporting the following error: "The term 'C:\Builds\agent_work\cb535ea3\Main' 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."
Have I configured the task incorrectly?
-- UPDATE: Here's a copy of the powershell task
Under the repository tab you need to include the script like below. If you have a directory of scripts you can select the folder instead.
We're running Atlassian's Bamboo build server 4.1.2 on a Windows machine. I've created a batch file that is executed within a Task. The script is just referenced in a .bat file an not inline in the task. (e.g. createimage.bat)
Within the createimage.bat, I'd like to use Bamboo's PLAN variables. The usual variable syntax is not working, means not replaced. A line in the script could be for example:
goq-image-${bamboo.INTERNALVERSION}-SB${bamboo.buildNumber}
Any ideas?
You are using the internal Bamboo variables syntax, but the Script Task passes those into the operating system's script environment and they need to be referenced with the respective syntax accordingly, e.g. (please note the underscores between terms):
Unix - goq-image-$bamboo_INTERNALVERSION-SB$bamboo_buildNumber
Windows - goq-image-%bamboo_INTERNALVERSION%-SB%bamboo_buildNumber%
Surprisingly, I'm unable to find an official reference for the Windows variation, there's only Using variables in bash right now:
Bamboo variables are exported as bash shell variables. All full stops
(periods) are converted to underscores. For example, the variable
bamboo.my.variable is $bamboo_my_variable in bash. This is related to
File Script tasks (not Inline Script tasks).
However, I've figured the Windows syntax from Atlassian's documentation at some point, and tested and used it as documented in Bamboo Variable Substitution/Definition:
these variables are also available as environment variables in the Script Task for example, albeit named slightly different, e.g.
$bamboo_custom_aws_cfn_stack_StringWithRegex (Unix) or
%bamboo_custom_aws_cfn_stack_StringWithRegex% (Windows)
I need to run a sql script while installing my program. I made a bat file which runs the script, and created a custom action on the commit of the setup project. The idea is the installer puts the file.sql(contained into my main project) in the installation path and then the custom action uses this file. How can this be possible?? Because doing this I get
this error: "There is a problem with this win installer package. A program run as part of the setup did not finish as expected.". Thanks.
You use SQLCMD to do this in your .bat file. A good example exists on TechRepublic. See figure B on how to configure your path. Another path example is shown in a brief article about a SQLCMD startup script; search for "startup script" on the page.