diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..0759bba --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,34 @@ +name: Java CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Get Fetch Tags + run: git -c protocol.version=2 fetch --tags --progress --no-recurse-submodules origin + if: "!contains(github.ref, 'refs/tags')" + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - name: Get Release Version + id: get_version + run: VERSION=$(./gradlew currentVersion -q -Prelease.quiet) && echo ::set-output name=VERSION::$VERSION + - name: Upload azure plugin jar + uses: actions/upload-artifact@v1.0.0 + with: + # Artifact name + name: Grails-Plugin-${{ steps.get_version.outputs.VERSION }} + # Directory containing files to upload + path: build/libs/azure-plugin-${{ steps.get_version.outputs.VERSION }}.jar \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3935b50 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,46 @@ +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +name: Upload Release Asset + +jobs: + build: + name: Upload Release Asset + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Gradle + run: ./gradlew build + - name: Get Release Version + id: get_version + run: VERSION=$(./gradlew currentVersion -q -Prelease.quiet) && echo ::set-output name=VERSION::$VERSION + - name: Create Release + id: create_release + uses: actions/create-release@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ steps.get_version.outputs.VERSION }} + draft: false + prerelease: false + - name: Upload Release Asset (jar) + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: build/libs/azure-plugin-${{ steps.get_version.outputs.VERSION }}.jar + asset_name: azure-plugin-${{ steps.get_version.outputs.VERSION }}.jar + asset_content_type: application/octet-stream \ No newline at end of file diff --git a/src/main/groovy/com/rundeck/plugins/azure/azure/AzureManager.groovy b/src/main/groovy/com/rundeck/plugins/azure/azure/AzureManager.groovy index 4b3a915..5becca0 100644 --- a/src/main/groovy/com/rundeck/plugins/azure/azure/AzureManager.groovy +++ b/src/main/groovy/com/rundeck/plugins/azure/azure/AzureManager.groovy @@ -25,6 +25,7 @@ class AzureManager { Region region boolean onlyRunningInstances boolean debug + boolean useAzureTags Azure azure @@ -91,7 +92,7 @@ class AzureManager { VirtualMachineSize size = azure.virtualMachines().sizes().listByRegion(virtualMachine.region()).find{ size-> size.name().equals(virtualMachine.size().toString())} - AzureNode azureNode = new AzureNode(virtualMachine,size) + AzureNode azureNode = new AzureNode(virtualMachine,size, useAzureTags) if(debug){ println ("--------- VM Mapping result ---------------") diff --git a/src/main/groovy/com/rundeck/plugins/azure/azure/AzureManagerBuilder.groovy b/src/main/groovy/com/rundeck/plugins/azure/azure/AzureManagerBuilder.groovy index 7dc8d19..76e291a 100644 --- a/src/main/groovy/com/rundeck/plugins/azure/azure/AzureManagerBuilder.groovy +++ b/src/main/groovy/com/rundeck/plugins/azure/azure/AzureManagerBuilder.groovy @@ -19,6 +19,7 @@ class AzureManagerBuilder { String tagValue boolean onlyRunningInstances Region region + boolean useAzureTags boolean debug @@ -99,6 +100,15 @@ class AzureManagerBuilder { return this } + /** + * @param onlyRunningInstances Only Running instances + * @return this builder + */ + AzureManagerBuilder useAzureTags(boolean useAzureTags){ + this.useAzureTags = useAzureTags + return this + } + /** * @param region the region to filter machines * @return this builder @@ -150,6 +160,7 @@ class AzureManagerBuilder { azure.setDebug(debug) azure.setTagName(this.tagName) azure.setTagValue(this.tagValue) + azure.setUseAzureTags(this.useAzureTags) return azure } diff --git a/src/main/groovy/com/rundeck/plugins/azure/azure/AzureNode.groovy b/src/main/groovy/com/rundeck/plugins/azure/azure/AzureNode.groovy index b1d3162..b4bc011 100644 --- a/src/main/groovy/com/rundeck/plugins/azure/azure/AzureNode.groovy +++ b/src/main/groovy/com/rundeck/plugins/azure/azure/AzureNode.groovy @@ -14,16 +14,18 @@ class AzureNode { String osName String osVersion - HashMap azureAttributes + Map azureAttributes VirtualMachineSize size + Map azureTags + AzureNode(){ } - AzureNode(VirtualMachine vm, VirtualMachineSize size) { + AzureNode(VirtualMachine vm, VirtualMachineSize size, boolean useAzureTags) { this.size = size //basic attributes @@ -72,6 +74,15 @@ class AzureNode { azureAttributes."${name}"=value } + if(useAzureTags){ + azureTags = [:] + vm.tags().findAll {key, value -> + if(key != "Rundeck-Tags"){ + azureTags.put(key, value) + } + } + } + azureAttributes.id = vm.id() azureAttributes.vmId = vm.vmId() azureAttributes.region = vm.region()?.name() diff --git a/src/main/groovy/com/rundeck/plugins/azure/azure/AzureNodeMapper.groovy b/src/main/groovy/com/rundeck/plugins/azure/azure/AzureNodeMapper.groovy index ab9837d..23ce669 100644 --- a/src/main/groovy/com/rundeck/plugins/azure/azure/AzureNodeMapper.groovy +++ b/src/main/groovy/com/rundeck/plugins/azure/azure/AzureNodeMapper.groovy @@ -135,6 +135,12 @@ class AzureNodeMapper { } } + if(node.getAzureTags()){ + node.getAzureTags().forEach{key, value -> + tagSet.add(key +":"+value) + } + } + return tagSet } diff --git a/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureResourceModelSource.groovy b/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureResourceModelSource.groovy index 155ab4b..61360b0 100644 --- a/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureResourceModelSource.groovy +++ b/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureResourceModelSource.groovy @@ -41,6 +41,7 @@ class AzureResourceModelSource implements ResourceModelSource { String tagName=configuration.getProperty(AzureResourceModelSourceFactory.TAG_NAME) String tagValue=configuration.getProperty(AzureResourceModelSourceFactory.TAG_VALUE) String extraMapping=configuration.getProperty(AzureResourceModelSourceFactory.EXTRA_MAPPING) + boolean useAzureTags=Boolean.parseBoolean(configuration.getProperty(AzureResourceModelSourceFactory.USE_AZURE_TAGS)) boolean debug=Boolean.parseBoolean(configuration.getProperty(AzureResourceModelSourceFactory.DEBUG)) @@ -61,6 +62,7 @@ class AzureResourceModelSource implements ResourceModelSource { .tagName(tagName) .tagValue(tagValue) .debug(debug) + .useAzureTags(useAzureTags) .build() } diff --git a/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureResourceModelSourceFactory.groovy b/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureResourceModelSourceFactory.groovy index 3e88c4d..9ffc653 100644 --- a/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureResourceModelSourceFactory.groovy +++ b/src/main/groovy/com/rundeck/plugins/azure/plugin/AzureResourceModelSourceFactory.groovy @@ -42,6 +42,7 @@ class AzureResourceModelSourceFactory implements ResourceModelSourceFactory,Desc public static final String TAG_NAME = "tagName" public static final String TAG_VALUE = "tagValue" public static final String RUNNING_ONLY = "onlyRunningInstances" + public static final String USE_AZURE_TAGS = "useAzureTags" public static final String DEBUG = "debugVm" @@ -87,6 +88,9 @@ class AzureResourceModelSourceFactory implements ResourceModelSourceFactory,Desc .property(PropertyUtil.bool(DEBUG, "Debug VM info", "Get the VM data on rundeck's log", false, "false", null,renderingOptionsConfig)) + .property(PropertyUtil.bool(USE_AZURE_TAGS, "Use Azure Tags", + "If this option is enabled, azure tags will be exporting as Rundeck node tags.", + false, "false", null,renderingOptionsConfig)) .build() @Override diff --git a/src/test/groovy/com/rundeck/plugins/azure/plugin/AzureVmListPluginSpec.groovy b/src/test/groovy/com/rundeck/plugins/azure/plugin/AzureVmListPluginSpec.groovy index e7c0533..e650185 100644 --- a/src/test/groovy/com/rundeck/plugins/azure/plugin/AzureVmListPluginSpec.groovy +++ b/src/test/groovy/com/rundeck/plugins/azure/plugin/AzureVmListPluginSpec.groovy @@ -45,7 +45,7 @@ class AzureVmListPluginSpec extends Specification{ AzureNode test = new AzureNode() test.name="test" test.hostname="test" - test.azureAttributes=[] + test.azureAttributes=[:] def vmList = [test]