Create a java project and compile with Azure pipeline

STEP 1. Create a java project with maven

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

STEP 2. Upload created my-app to GIT or Azure repo

STEP 3. Create my-app.yml as pipeline

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more: this is dummy commit
# https://aka.ms/yaml

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'

- task: Maven@3
  inputs:
    mavenPomFile: 'my-app/pom.xml' 

- publish: $(System.DefaultWorkingDirectory)
  artifact: 'my-app-1.0-SNAPSHOT.jar'


- task: DownloadPipelineArtifact@2
  inputs:
    buildType: current
    artifact: 'my-app-1.0-SNAPSHOT.jar'


STEP 4. Run the pipeline and check the my-app-1.0-SNAPSHOT.jar

Jython Script to create MINE web data-source and JDBC provider

# Jython Script to create MINE web data-source and JDBC provider. 
#

#Import Statements
import os
import re
import sys

# Create JDBC provider for MINE oracle database.
def createMINEJDBCProvider():
    server = '/Server:server1'
    # Set the Node ID
    serverID = AdminConfig.getid(server)
    print 'Server ID:' + serverID

    #Configuring J2c auth
    userAlias='test/MINEDBUser'
    alias = ['alias', userAlias]
    userid = ['userId', 'MINEDB']
    password = ['password', 'MINEpass']
    jaasAttrs = [alias, userid, password]
    security = AdminConfig.getid('/Security:/')
    print 'security:'+security
    j2cUser=AdminConfig.create('JAASAuthData', security, jaasAttrs)
    AdminConfig.save()
    print 'Creating MINE User sucessfull'

    # Test to see if the provider has already been created.
    MINEJDBCprovider = AdminConfig.getid('/JDBCProvider:Oracle JDBC Driver/')
    if len(MINEJDBCprovider) == 0:
        providerName='Oracle JDBC Driver'
        print 'creating Oracle JDBC provider on server:'+serverID
        print 'JDBC provider Name:'+providerName
        MINEJDBCprop1 = ['name', providerName]
        MINEJDBCprop2 = ['description','Oracle JDBC Driver for MINE Application']
        MINEJDBCprop3 = ['implementationClassName','oracle.jdbc.pool.OracleConnectionPoolDataSource']
        MINEJDBCprop4 = ['classpath','${ORACLE_JDBC_DRIVER_PATH}/ojdbc6.jar']
        MINEJDBCprops=[MINEJDBCprop1,MINEJDBCprop2,MINEJDBCprop3,MINEJDBCprop4]
        providerID = AdminConfig.create('JDBCProvider', serverID, MINEJDBCprops)
        AdminConfig.save()
        print 'Creating Oracle JDBC provider on server sucessfull with provider:'+providerID
        createMINEDataSource()
    else:
        print 'oracle provider exists:'+MINEJDBCprovider


def createMINEDataSource():
    providerName='Oracle JDBC Driver'
    userAlias='test/MINEDBUser'
    MINEJDBCprovider = AdminConfig.getid('/JDBCProvider:Oracle JDBC Driver/')
    MINEDataSource = AdminConfig.getid('/JDBCProvider:'+providerName+'/DataSource:MINEDB/')
    if len(MINEDataSource) == 0:
        # Set the datasource attributes
            MINEDSprop1 = ['name', 'MINEDB']
            MINEDSprop2 = ['jndiName', 'jdbc/MINEdb']
            MINEDSprop3 = ['description', 'MINE database']
            MINEDSprop4 = ['datasourceHelperClassname', 'com.ibm.websphere.rsadapter.Oracle11gDataStoreHelper']
            MINEDSprop5 = ['authDataAlias' , userAlias]
            mapConfigprop=["mappingConfigAlias", "DefaultPrincipalMapping"] 
            mapConfigs=[MINEDSprop5 , mapConfigprop] 
            mappingConfig=["mapping", mapConfigs]

            MINEDSprops = [MINEDSprop1, MINEDSprop2, MINEDSprop3, MINEDSprop4, MINEDSprop5, mappingConfig]
            MINEDataSource = AdminConfig.create('DataSource', MINEJDBCprovider, MINEDSprops)

            #Set the DB URL
            propSet = AdminConfig.create('J2EEResourcePropertySet', MINEDataSource, [])
            AdminConfig.create('J2EEResourceProperty', propSet, [["name", "URL"], ["value", "jdbc:oracle:thin:@myserver:1523:MINED2"]])

            AdminConfig.save()
            print 'Creating MINE JDBC Datasource on server sucessfull with datasource:'+MINEDataSource

    else:
        print 'MINE Datasource already exists in the server:'+MINEDataSource
        print 'Testing datasource connection'
        print AdminControl.testConnection(MINEDataSource)

try:

    print 'start'
    createMINEJDBCProvider()
    createMINEDataSource()
    print 'end'
except:
    print "***** Unexpected error while creating JDBC datasource:", sys.exc_info(), " *****"
    raise

create ansible playbook for WebSphere application deploy and uninstall

STEP 1. for WebSphere application deployment, we have two files: deploy.sh and deploy.yml

########deploy.sh############
/app/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/wsadmin.sh -conntype none -lang jython -c "AdminApp.install('/home/vadmin/SampleWebApp.war', ['-appname', 'PlantsByWebSphere', '-contextroot', 'my_uri', '-usedefaultbindings', '-server', 'server1'])"

########deploy.yml############
- hosts: was
  tasks:
  - name: Ansible copy file to remote server
    copy:
            src: /home/vadmin/SampleWebApp.war
            dest: /home/vadmin/SampleWebApp.war
  - name: Copy and Execute the script
    script:
            /home/vadmin/deploy.sh
########## start application ##################
cat start_app.py
appManager = AdminControl.queryNames('type=ApplicationManager,process=server1,*')
AdminControl.invoke(appManager, 'startApplication', 'PlantsByWebSphere')

########## ansible debug/check commands##################
ansible-playbook deploy.yml --start-at-task="Copy and Execute the script"
ansible-playbook deploy.yml --syntax-check
ansible-playbook deploy.yml --step

STEP 2. uninstall the apps

################undeploy.sh##############
/app/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/wsadmin.sh -conntype none -lang jython -c "AdminApp.uninstall('PlantsByWebSphere')"

#############undeploy.yml####################
- hosts: was
  tasks:
  - name: Copy and Execute the script
    script:
            /home/vadmin/undeploy.sh