vbareporting-servicescommand-linerdl

How to run build/deploy only on *.rdl files


I'm running the below build command from CMD (runs on windows slave from jenkins):

 bat "devenv.com MyProject.sln /Build Release"

My output to bin\Release are *.rdl files + *.obj files + *.rds files

After that, I'm running the below deploy command:

  bat ' rs.exe -i pipeline/ssrs/Upload_Multiple_RDL_files.rss -s "{My report server}" -v FILE_NAME="pipeline/ssrs/ConfigurationFile.txt" '

and here I get error once it reached non rdl files:

 The definition of this report is not valid or supported by this version of Reporting Services

Is there a way to avoid it? for example, run build and see only the *.rdl files in bin\Release or modify Upload_Multiple_RDL_files.rss VB script which I took from this answer to run only on *.rdl files?

Upload_Multiple_RDL_files.rss content:

'Script Starting Point
' Script to deploy report to report server
' EXECUTE VIA COMMAND LINE

DIM definition As [Byte]() = Nothing
DIM warnings As Warning() = Nothing

Public Sub Main()

' Variable Declaration
        Dim TextLine As String = ""
        Dim LocalDir As String = ""
        Dim ServerDir As String = ""
        Dim definition As [Byte]() = Nothing
        'Dim warnings As Warning() = Nothing

' Reading Configuration Text file and assigning the values to variables
        If System.IO.File.Exists(FILE_NAME) = True Then
            Dim objReader As New System.IO.StreamReader(FILE_NAME)
            Do While objReader.Peek() <> -1
                TextLine = objReader.ReadLine()
                Dim parts As String() = TextLine.Split(New Char() {","c})
                'TextLine & objReader.ReadLine() '& vbNewLine
                LocalDir = parts(0)
                ServerDir = parts(1)

                Dim path As String = LocalDir
                Dim fileEntries As String() = Directory.GetFiles(path)
                Dim fileFullPath As String = ""
                For Each fileFullPath In fileEntries


' Deploying the Reports
                    Try
                        Dim stream As FileStream = File.OpenRead(fileFullPath)
                        Dim NameWithExt As String = fileFullPath.Replace(path, "")
                        Dim NameOnly As String = NameWithExt.Replace(".rdl", "")
                        definition = New [Byte](stream.Length-1) {}
                        stream.Read(definition, 0, CInt(stream.Length))

      warnings = rs.CreateReport(NameOnly, ServerDir, True, definition, Nothing)

      If Not (warnings Is Nothing) Then
        DIM warning As Warning
        For Each warning In warnings
        Console.WriteLine(warning.Message)
        Next warning
      Else
       Console.WriteLine("Report: {0} PUBLISHED!", NameOnly)
      End If

     Catch e As IOException
      Console.WriteLine(e.Message)
     End Try
    Next fileFullPath
   Loop
         Else

            Dim MsgBox as String = "File Does Not Exist"

        End If
End Sub

'End of the Script

Solution

  • I'm not VB expert, but the below worked for me after adding this if condition:

    If NameWithExt Like "*rdl*" Then

    full script:

    'Script Starting Point
    ' Script to deploy report to report server
    ' EXECUTE VIA COMMAND LINE
    
    DIM definition As [Byte]() = Nothing
    DIM warnings As Warning() = Nothing
    
    Public Sub Main()
    
    ' Variable Declaration
            Dim TextLine As String = ""
            Dim LocalDir As String = ""
            Dim ServerDir As String = ""
            Dim definition As [Byte]() = Nothing
            'Dim warnings As Warning() = Nothing
    
    ' Reading Configuration Text file and assigning the values to variables
            If System.IO.File.Exists(FILE_NAME) = True Then
                Dim objReader As New System.IO.StreamReader(FILE_NAME)
                Do While objReader.Peek() <> -1
                    TextLine = objReader.ReadLine()
                    Dim parts As String() = TextLine.Split(New Char() {","c})
                    'TextLine & objReader.ReadLine() '& vbNewLine
                    LocalDir = parts(0)
                    ServerDir = parts(1)
    
                    Dim path As String = LocalDir
                    Dim fileEntries As String() = Directory.GetFiles(path)
                    Dim fileFullPath As String = ""
                    For Each fileFullPath In fileEntries
    
    
    ' Deploying the Reports
                        Try
                            Dim stream As FileStream = File.OpenRead(fileFullPath)
                            Dim NameWithExt As String = fileFullPath.Replace(path, "")
                            Dim NameOnly As String = NameWithExt.Replace(".rdl", "")
                            definition = New [Byte](stream.Length-1) {}
                            stream.Read(definition, 0, CInt(stream.Length))
          
                            If NameWithExt Like "*rdl*" Then
                                warnings = rs.CreateReport(NameOnly, ServerDir, True, definition, Nothing)
                                Console.WriteLine("Report: {0} PUBLISHED!", NameOnly)
                            End If
    
                        Catch e As IOException
                            Console.WriteLine(e.Message)
                        End Try
                    Next fileFullPath
                    Loop
            Else
                Dim MsgBox as String = "File Does Not Exist"
            End If
    End Sub
    
    'End of the Script