Like the question says, how can I do that? This is the script I am currently using through the generation of a .dacpac file, but I’ve seen that this can be done with a powershell script instead of AzureCLI@2?
I tried this – This is the AzureCLI@2 script:
- task: AzureCLI@2
inputs:
azureSubscription: '$(azureSubscription)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
set -e
echo "Starting DACPAC extraction..."
# Obtain an access token
echo "Obtaining access token..."
accessToken=$(az account get-access-token --resource https://database.windows.net/ --query accessToken --output tsv)
echo "Access token obtained."
# Check if the access token was retrieved
if [ -z "$accessToken" ]; then
echo "Failed to obtain access token. Exiting."
exit 1
fi
# Create directories if they don't exist
mkdir -p $(Build.SourcesDirectory)/temp/DACPAC
mkdir -p $(Build.SourcesDirectory)/some/ran/dir/
# Extract DACPAC file to a temporary directory
echo "Extracting DACPAC file..."
./sqlpackage/sqlpackage /Action:Extract /SourceServerName:$(sqlServerName) /SourceDatabaseName:$(sqlDatabaseName) /TargetFile:$(Build.SourcesDirectory)/temp/DACPAC/$(sqlDatabaseName).dacpac /AccessToken:$accessToken
# Unzip the extracted DACPAC file
echo "Unzipping DACPAC file..."
unzip -o $(Build.SourcesDirectory)/temp/DACPAC/$(sqlDatabaseName).dacpac -d $(Build.SourcesDirectory)/temp/DACPAC
# Move extracted schema files to the target directory, replacing existing files
echo "Replacing existing .sql files with updated schema..."
find $(Build.SourcesDirectory)/temp/DACPAC -name '*.sql' -exec cp -v {} $(Build.SourcesDirectory)/some/ran/dir/ ; 2>error.log
echo "Schema extraction and replacement completed."
echo "Listing files in target directory..."
ls -l $(Build.SourcesDirectory)/some/ran/dir/
ls -l $(Build.SourcesDirectory)/temp/DACPAC
# Commit and push the changes
echo "Committing and pushing changes..."
cd $(Build.SourcesDirectory)
git config --global user.email "$(sqlAdminLogin)"
git config --global user.name "Name"
git add --all
git status
git commit -m "Update schema files from DACPAC extraction" || echo "No changes to commit"
git push https://$(azureDevOpsPat)@dev.azure.com/my/git/repo/here HEAD:$(Build.SourceBranch) --force
ls -l $(Build.SourcesDirectory)/some/ran/dir/
echo "Changes committed and pushed."
and I was expecting it to commit the files to the designated location, but it just says detached head. Trying to change the repo branch through using checkout and creating a temporary branch doesn’t work either.
WorkingProgrammer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1