Hi tarun k
To dynamically inject the username and password into your Liquibase properties file during pipeline execution, you can use Azure DevOps pipeline variables.
Please follow the below steps to resolve this issue:
- In your Azure DevOps pipeline, you can define variables for username and password. Go to Pipelines -> Select your Pipeline -> Edit -> Variables -> Add variable. Make sure to mark the password parameter as secret in the pipeline definition.
- Create a properties file (e.g., liquibase.properties) in your repository with the following content:
liquibase.loglevel=debug username=$(username) password=$(password) changeLogFile=changeset_master.xml url=test.com
- YAML file:
trigger: - main pool: vmImage: 'ubuntu-latest' variables: username: '' password: '' parameters: - name: username type: string default: '' displayName: 'Enter Username' - name: password type: string default: '' displayName: 'Enter Password' isSecret: true jobs: - job: LiquibaseJob steps: - checkout: self - script: | echo "Updating properties file with dynamic values" sed -i "s/username=.*/username=$(username)/" liquibase.properties sed -i "s/password=.*/password=$(password)/" liquibase.properties displayName: 'Update properties file' - script: | echo "Running Liquibase commands" # Add your Liquibase command here, e.g.: # liquibase --changeLogFile=changeset_master.xml update displayName: 'Run Liquibase'
- Alternatively, you can try the below YAML file:
In your liquibase.properties file (in repo):liquibase.loglevel=debug username=${DB_USERNAME} password=${DB_PASSWORD} changeLogFile=changeset_master.xml url=test.com
trigger: - main variables: # These will be passed at runtime or set as secret variables DB_USERNAME: $(username) DB_PASSWORD: $(password) stages: - stage: LiquibaseUpdate displayName: 'Run Liquibase Update' jobs: - job: RunLiquibase displayName: 'Execute Liquibase' pool: vmImage: 'ubuntu-latest' steps: - checkout: self - task: Bash@3 name: InjectSecrets displayName: 'Inject credentials into liquibase.properties' inputs: targetType: 'inline' script: | echo "Injecting credentials..." sed -i "s|username=.*|username=${DB_USERNAME}|" liquibase.properties sed -i "s|password=.*|password=${DB_PASSWORD}|" liquibase.properties - task: Bash@3 displayName: 'Run Liquibase' inputs: targetType: 'inline' script: | liquibase --defaultsFile=liquibase.properties update
- When you run the pipeline, Azure DevOps will prompt the user to enter the username and password.
Hope this helps!
Please Let me know if you have any queries.
If you found the information helpful, please click "Upvote" on the post to let us know and consider accepting the answer as the token of appreciation. Thank You.